3 ms·
Assuming your purpose is learning rather than writing a practical project, I would go in the order of C => C++ => Rust. Each of them builds on concepts of the
by nostrademons 11y ago
Assuming your purpose is learning rather than writing a practical project, I would go in the order of C => C++ => Rust. Each of them builds on concepts of the previous.
It is easier to learn C++ if you already know the distinction between value vs. pointer types, if you're already familiar with C syntax, if you already know how to manage memory manually, and if you already know how to use functions, function pointers, and opaque types to create an API. C will teach you all of those.
It is easier to learn Rust if you already know about RAII, ownership, generics, both run-time and compile-time polymorphism, and move semantics. C++ will teach you all of those (in its C++11 and C++14 variants, at least).
- DerekL 11y agoYou should only learn all three languages if you want to know all three languages. Learning C as a stepping stone to C++ is a waste of time. You might think it's a good idea, because C++ is based on C, and most of the features of C are available in C++. But writing good C code requires idioms that are useless in C++. For instance, suppose you need to write a function that opens a file, reads the contents into a some data structure, and then returns a result. Before the function returns, it needs to free the memory in the data structure and close the file. If you write this in C, you either have to make sure you only return at the end, or use nested "if" statements, or use "goto" statements. But in C++, you don't have to worry about this, because the object destructors will handle it.
- rnovak 11y agoIf you go into it as a means to an end, then yes, it probably would be a waste of time. But....if you actually approach it as an opportunity to expose yourself to new ways to think about problems, I don't think that would ever be a waste of time. I disagree that you'll never use C idioms in C++ or Rust, but even IF that were true, there's absolutely no way that having a better understanding of what the underlying hardware is doing is a bad thing.
- dbaupp 11y agoRust (e.g. starting with the book[1]) will also teach you about RAII, generics, polymorphism, and ownership and move semantics... the latter two in a far more explicit and clearer (IMO) way than C++ too. That said, of course, without C/C++ experience, one won't have had the "fun" of the crashes and weird bugs that are caused by not paying attention to ownership in C and C++ (and, hence, I guess, the motivations for some of Rust's design decisions might not be so clear). [1]: http://doc.rust-lang.org/book/ http://doc.rust-lang.org/book/
- backslash_16 11y agoMy purpose is mainly learning for now and I'm not under time pressure. This sounds really great, along with everyone's advice about learning C++11 and C++14 when I get there. Although C++ having a lot of language features (like destructors built it) is appealing. HN definitely helped me figure out what to do. I've really liked what the C book has taught me so far, because nothing is hidden, especially the part about building an object oriented programming language and the side projects of communicating over ports. Before that, I academically knew that a method is just a function with the object passed/bound as a "hidden" first parameter, with a keyword to make referencing it easier but building it solidified it.