4 ms·
Even such basics as initialization is full of traps in C++, its truly language thats awful to produce anything safe with. C on the other hand isnt a bad languag
by Cloudef 3y ago
Even such basics as initialization is full of traps in C++, its truly language thats awful to produce anything safe with. C on the other hand isnt a bad language, but C's problem comes from the horrible standard library and bad standard. You can create much better C by passing -fno-strict-aliasing -ftrapv -fsigned-char to the compiler even now. Heck rust's unsafe is more unsafe than C. "C" could be improved with a better compiler that ignores the standard, but perhaps it wouldnt be C anymore even if the syntax remained the same.
C++ problem is not helped by the compilers either, shoutouts to msvc++ accepting absolutely wrong and horrible code by default.
- amluto 3y agoIMO the problem with C isn’t just the horrible standard library. It’s that you can’t make a better standard library — the language constructs needed to abstract almost anything don’t really exist.
- Cloudef 3y agoThe standard library consists many functions that simply should be dropped. All the globals like errno, locale should be removed. Instead of global allocator, allocator struct should be passed around (zig). Headers like stddef and stddint in the standard library should be in the language instead. https://github.com/Cloudef/zig-budoux/blob/master/src/c.zig#L9 https://github.com/Cloudef/zig-budoux/blob/master/src/c.zig#...
- amluto 3y agoAll true, but that still doesn’t mean that there will ever be a genuinely nice string type or map from string to int or a nice HTTP or any similar thing where some of the data types are dynamically sized.
- Cloudef 3y agostruct and few functions and you get there. Look at zig's std lib. "String" type is also IMO anti-pattern https://mortoray.com/the-string-type-is-broken/ https://mortoray.com/the-string-type-is-broken/ People often complain about null terminated "strings" in C, but I don't really see them as a problem. It rarely is performance bottleneck, and when it is you can opt for your own "string type". There is also bstring that's compatible with these strings but prepend header to the data which contains the length. That said I wish C had language level slicing.
- thesuperbigfrog 3y ago>> "C" could be improved with a better compiler that ignores the standard, but perhaps it wouldnt be C anymore Then it wouldn't be C. C is 52 years old. For most use cases, there are better options. Instead of trying to apply bandages to C or C++, why not move to something better? Legacy code written in C or C++ can be maintained or rewritten as needed. New code should not be written in C or C++ because it is not safe--thus the White House warning.
- Cloudef 3y agoI've already moved to zig since it's the only real C alternative out there right now. I'm just making a point C itself as a written language is not bad. You could make something that is very similar, but avoids most of the common issues with C (which are much less than with C++). C won't die and interop will be the C ABI for long time still.