3 ms·
This is totally backwards advice. If you're going to teach C/C++, it makes far more sense to start with modern c++ which takes care of so much for you. std::str
by kllrnohj 5y ago
This is totally backwards advice. If you're going to teach C/C++, it makes far more sense to start with modern c++ which takes care of so much for you. std::string, std::vector, std::unique_ptr, and std::shared_ptr all alone make C++ far more approachable (and readable!) than C. And you can just entirely avoid pointers for a while, avoiding the need to cover things like avoiding returning pointers to stack values until much, much later.
After that you can then peel back the layers and discuss things like manual memory allocations, how vectors work under the covers, etc...
But C is an awful language to start with. It's incredibly complex to actually use and full of sharp edges. The grammar simplicity betrays the extreme mental complexity to actually use it without crashing or leaking memory everywhere. Not to mention the huge overhead in just doing simple things since nothing is included, and nothing is straightforward (like containers like hashmaps - hugely complex in C, trivial as heck in every other language)
And that's before you get into the fact that you can't even just learn C. You have to also learn macros at the same time to actually do anything effectively, which is basically a second language full of its own quirks and problems. With C++ you can reasonably avoid learning macros for a long, long time.
- LAC-Tech 5y agoC 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.