2 ms·
C may be the best example of "worse is better", but every time I do something non-trivial with it, I wish there was something better: * Undefined behavior, the
by bxparks 2y ago
C may be the best example of "worse is better", but every time I do something non-trivial with it, I wish there was something better:
* Undefined behavior, there are apparently over 100 of them. I can probably name about 5, maybe 10. Will the compiler warn me if I accidentally trigger undefined behavior? Of course not, it assumes that I am super-human who never makes a mistake.
* Code sharing using '#include', god I hate 'em.
* No namespaces, which means a single global namespace for all functions.
* Strings: every time I have to manipulate strings in C, I want to shoot myself.
* Arrays decaying into pointers, very clever, causing so much misery.
* Array length decoupled from the array pointer. No way to pass around both of them together, and checked automatically by the compiler.
* The C preprocessor #define magic. Love 'em when they are mine, hate 'em when they are someone else's. Hate 'em even more when they are mine 6 months later.
* The #define/#ifdef spaghetti code. There ought to be better ways to support multiple architectures.
Those are just off the top of my head. I'm sure I could come up with a few more items.
- JonChesterfield 2y agoThe UB is a lot more manageable if you pass nostrict-aliasing and similar to the compiler, or if you use a compiler that doesn't do that style of trickery. The includes and raw pointers are a build your own abstraction thing. Annoying if the abstraction you're building is the one a different language gives you to work with. For example, a struct with multiple arrays of the same length - in C that's multiple pointers and one size, in other languages that's probably multiple sizes and asserts that they haven't diverged. It's not a perfect language but it's really rather good.