4 ms·
C is more useful to a broader range of programmers than C++. If your goal is to maintain million LOC C++ projects and make that your whole career, then spending
by LAC-Tech 5y ago
C is more useful to a broader range of programmers than C++. If your goal is to maintain million LOC C++ projects and make that your whole career, then spending the considerable time effort in C++ is worth it. But the whole world speaks C, it's so much simller. If your goal is to wrap existing libraries or speed up a hot spot in a language like python, plain C is a no brainer.
- kllrnohj 5y agoC as an ABI is basically its own thing. And can be implementated in C++ anyway just with 'extern "C"' slapped onto the function. But it definitely doesn't make sense to start teaching anything at this level with "here's how you design a stable API/ABI". That's a skill set that relatively few need to know
- LAC-Tech 5y agoC as an ABI is basically its own thing. And can be implementated in C++ anyway just with 'extern "C"' slapped onto the function. Yeah, so learning C is required to write a portable C++ lib/extension, so you know what can go in `extern "C"` and what can't. At that point, you might as well do the whole thing in C and benefit from the super fast compile times. But it definitely doesn't make sense to start teaching anything at this level with "here's how you design a stable API/ABI". That's a skill set that relatively few need to know Fair enough, computing is a big field. For me non GC'd languages are something I dip into for a particular task. The mission is to get in, write the bare minimum, and get out as soon as possible. If I wanted to "move in" as it were, the (substantial!) time investment to master C++ or Rust is probably worth it.
- kllrnohj 5y ago> Yeah, so learning C is required to write a portable C++ lib/extension, so you know what can go in `extern "C"` and what can't. At that point, you might as well do the whole thing in C and benefit from the super fast compile times. Neither claim there is really true at all. Learning how to write a stable extern C ABI really doesn't require learning C at all, nor even actually using C. Eg, I can put C++ classes in extern C functions just fine, as long as I do so as opaque pointers. Which you need to do for C as well, or use one of the other struct versioning schemes. And then similarly why would I bother with C's nightmare of data structures or error handling in the implementation when I can use C++ instead and have it be a walk in the park? Marginally faster compile times isn't remotely worth it when you're compiling more often to fix more bugs. Finally no you don't need C ABI to have a portable C++ library. You only need a C ABI to have a backwards compatible library as a prebuilt (and even that isn't strictly true, see eg libc++), which is a very very small niche within a niche. Like you're only doing that if you're an OS platform. Everyone else just ships C++ APIs and it works great (eg, abseil, folly, boost, skia, etc...)
- LAC-Tech 5y agoWe're talking past each other here. When I say "portable" I mean easy to use the resulting lib in non C or C++ languages. As for why would you bother? I don't know, I guess you wouldn't, because you know C++ really well. I've been paid for it before, know it OK, and at the end of the day I'm more productive in C for the problems I want to drop down to that level for.