4 ms·
>why to use C over C++ today? Simplicity. You can keep the entire language in your head and everything is explicit with no "magic" involved. That said, you mi
by rramadass 4y ago
>why to use C over C++ today?
Simplicity. You can keep the entire language in your head and everything is explicit with no "magic" involved.
That said, you might want to start moving to C++ slowly, first as a "better C with user-defined types" and then to OOP/Generic/etc. programming goodness which gives you a much larger design space.
- JonChesterfield 4y agoThere's pretty much all the same compiler magic either way. At least C++ gives you placement new and std::launder, C gives you malloc and you cross your fingers that the compiler's alias analysis goes your way for now.
- WalterBright 4y ago> You can keep the entire language in your head Explain, without looking it up, exactly how macro expansion works. (Don't feel bad. I've written 3 implementations of the CPP, and still couldn't tell you how it works without carefully reading it again.)
- ndesaulniers 4y agoRight, you can "hide" what's going on in otherwise proceedural C codebases w/ the preprocessor. To be more charitable to OP, in C++ you can further "hide" what's going on with destructors in addition to the preprocessor. (I like RAII and hope more C programmers can learn to appreciate it. I have fixed and reviewed many fixes in the Linux kernel for -Wsometime-initialized because error handling using goto is a constant source of programmer mistakes introducing UB). I'd love to chat sometime about approaches to implementing a CPP!
- int_19h 4y agoIt's not even that macros can hide complexity. It's that the specification for the C preprocessor is itself rather complicated and non-obvious - e.g. what happens when nesting even simple macros, or even something as basic as tokenization.
- WalterBright 4y agoRight, I was talking about the specification, not the use. How people use the preprocessor is by just fiddling with it till it delivers what they want, then they move on.
- mhh__ 4y agoYou can keep the language in your head, but there's good empirical evidence you can't keep the code in your (companies collective) head.