6 ms·
It kind of depends on what you need out of C. The only real reasons left to use C in the wild are: * Legacy code * Embedded (including drivers, bare metal etc
by qsort 6y ago
It kind of depends on what you need out of C. The only real reasons left to use C in the wild are:
* Legacy code
* Embedded (including drivers, bare metal etc.)
* Portability, FFI, etc.
Performance used to be another major reason, but in $CURRENT_YEAR, if that's your goal, C++ and Rust are just as performant and there's very little reason not to opt into them.
The other major reason to learn C is that it's a great "hardcore introductory" language that will expose you to foundational concepts like pointers and memory management (it's really hard to understand what problems Rust is trying to solve if you're not familiar with malloc and free, for instance), but if you're already programming that's less of an issue.
- 0x008 6y agoWell for me one objective definitely would be to better my understanding of gnu tools, gcc etc. But for the most part, yes it is about "foundational concepts". A lot of the time when you learn system level programming people will refer to certain quirks or terms from the C world.
- qsort 6y agoIf you're just looking for a cursory introduction to the underlying concepts, I agree with the other comments that K&R is what you are looking for. I'd add the caveat that due to the fact that C is a tiny language with a tiny standard library, most code you'll see in the wild uses custom concepts/libraries/object models on top of C. So for most practical purposes, there isn't really "C" as much as there is "unix programming C", or "embedded C", or whatever else have you, and all of them add a thick layer on top of the core language.
- pjc50 6y agoI would still suggest that people learn C before attempting C++; while someone with C# or Java experience could probably do well in a "modern C++" codebase, as soon as they go off-piste into memory allocation and pointers they're in for surprises. (Is there anyone who learns Rust who isn't already a proficient but frustrated C++ programmer?)
- qsort 6y agoCompletely agree, that was part of the point I was making, for example, I doubt I would ever have understood RAII had I never seen malloc. Parent was suggesting they are already a programmer, so I assumed they already had at least a grasp of how pointers and manual memory management work. If one happens to lack such knowledge, I agree learning C is an excellent first step.
- asveikau 6y agoI understood malloc very well long before RAII made sense to me. I think what made RAII seem like a good idea was seeing a large C code base at a major company which had a consistent approach to cleanup and error handling. It's very possible to write good code that way, but it takes manual effort, discipline, consistency. At that point I understood that RAII was about letting the compiler handle what I was already doing in C.
- nicoburns 6y ago> Is there anyone who learns Rust who isn't already a proficient but frustrated C++ programmer? Yes, I learnt Rust as a JavaScript/PHP/Python programmer who needed better performance for a project, and I'd thoroughly recommend it as a first low-level language. I found it much easier to learn than C++. There were a few new concepts to learn, but: - There were far fewer than C++. - The Rust Book provided a free and very approachable resource for learning them. - The Rust compiler gave me immediate feedback if I was doing something wrong (no unexpected bugs in production) - Most of my JS skills translated pretty straightforwardly - /r/rust has a very helpful community which filled in any gaps that weren't covered elsewhere. C is simple when you're working with toy examples, but as soon as you try to do anything moderately complex the complexity quickly jumps. e.g. If I wan't to use something as basic as a HashMap this is a trivial import in Rust or C++, but a non-trivial task in C. You either have to build/import a library (which is not that easy in C), or write one yourself! Same for string operations!
- ognarb 6y agoI would recommend you to watch "CppCon 2015: Kate Gregory “Stop Teaching C"" https://www.youtube.com/watch?v=YnWhqhNdYyk https://www.youtube.com/watch?v=YnWhqhNdYyk
- smoe 6y agoI had C as an introductory language and I didn’t perceive it as very hardcore, because we were doing the most basic things. Key is in my opinion, that you do projects aligned with your current programming skill level. I have never used C professionally, so I never worked with a large, complex code base. But I think getting the foundational concepts from it as a first language has helped a lot along the way picking up and switching between languages.
- coldpie 6y agoStrong disagree. Unless you're using it as "C with classes", C++ is a nightmare hell language that you should only use if you're forced to by your environment. Stay far away. C is a fine language, but it is from the 60s and 70s and feels like it. Rust is very nice, although poor for half-assed prototyping (which is actually maybe a good thing). Both are fine choices for systems-level programming.
- glouwbug 6y agoI've been working on this which you might find of use: https://github.com/glouw/ctl https://github.com/glouw/ctl
- dvfjsdhgfv 6y agoThat's interesting. Do I understand correctly though that the performance of CTL is mostly on a par with that of the STL?
- glouwbug 6y agoYes, I'd say at worst its 20% slower. The implementation is naive and readable (and therefor hackable). I did not have the time to implement all the heuristics that make STL as fast as it. The goal is hackability and ease of use (think text book function examples), while giving embedded engineers (or even desktop engineers with an aversion to C++) a chance to focus on getting their work done. That, and lighting fast compile times, where programming feels like (oh, the heresy) a _drastically reduced C++_.
- ku-man 6y agoNot quite. I use C to interact with scientific libraries and to do some image processing. I would like to learn and use Rust but is still lacking in the scientific libraries department. I avoid C++ because it's a nightmare of complexity.