9 ms·
Ask HN: C, C++, or Rust which language to learn next?
I'm mostly new to C (have gone through about half of Learn C The Hard Way) and completely new to C++ and Rust. For my day job I use C#, JavaScript, SQL, and a little Python.
I got the Bjarne Stroustrup book Programming: Principles and Practice Using C++ as a gift and now I'm trying to figure out if I should keep digging into C, jump ship to learning C++ or take a look at Rust.
I started learning C because I wanted to dig into a non GC language and get a little "closer to the metal", not because I need it for my day job. My friend got me the C++ book because he said I should spend my time learning a language that I might end up using in a job but that's not my primary concern right now.
Lastly I started looking at Rust because the HN search (https://hn.algolia.com/?query=rust%20c&sort=byPopularity&prefix&page=0&dateRange=all&type=story) returned a lot of interesting comparison beween it and C/C++. They all make it sound like Rust is an easier to learn systems language which lowers the chance of making memory related errors and has a few nice features to make the code easier to read and understand.
Does anybody have opinions on which language I should learn for the purpose of understanding how code interacts with the computer at a low level better, manual memory management, and learning how to deal with pointers (instead of C#/Java references)? Any personal preference out of all the languages?
- nostrademons 11y agoAssuming 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.
- untothebreach 11y agoI don't think you need to learn C and C++ as a prerequisite for learning Rust, but I still think C is worth learning. The concepts that you would learn with C++ can be learned just as well by learning Rust, so I would skip C++ if I were you. If you decide to learn Rust, the Book[1] is, I think, the best way for you get started, seeing as you already have experience programming. 1: http://doc.rust-lang.org/book/ http://doc.rust-lang.org/book/
- sudeepj 11y ago> I don't think you need to learn C and C++ as a prerequisite for learning Rust While this is true, it's just that only after knowing C++ pain points one can appreciate Rust more :o)
- tjr 11y agoI'm currently starting a new project in C++, because various logistics conspire together to make that the ideal choice. If that weren't the case, well, I personally do not like C++ much, though sticking with C++11 style over older C++ paradigms seems like an improvement. Just picking a low-level systems language for my own fun and edification, I'd still learn C because it is so ubiquitous, but I for one hope that something more like Rust is the future.
- jbandela1 11y agoLearn C++. You will have the opportunity to learn low-level features but know how to wrap them up inside highly performant, high-level components. Rust is interesting, but I think it will remain an interesting language outside the mainstream without any major commercial backers (Mozilla does not count). In addition, C++ is taking a lot of the ideas from Rust and incorporating them along with tooling that will provide 95+% of the value of Rust while still keeping the advantages of C++ (see https://www.youtube.com/watch?v=hEx5DNLWGgA https://www.youtube.com/watch?v=hEx5DNLWGgA) What is interesting with C++ is that although a lot of vendors are pushing their own languages - Microsoft with C#, Apple with Swift, Google with Go, Facebook with Hack, Mozilla with Rust - they are all deeply involved with C++ because C++ powers their mission-critical code. Another way of putting it would be that despite all the promotion if all of Mozilla's Rust code were eliminated tomorrow nobody would notice, but if all of Mozilla's C++ code were eliminated, it would cease to exist. Also, C++ is rapidly evolving and by learning Modern C++ 14 now, you can avoid a lot of the mistakes of C++ that were common in the past and write safe, elegant code. C++ is also experiencing a renaissance (see https://www.jetbrains.com/cpp/cpp-today-oreilly/ https://www.jetbrains.com/cpp/cpp-today-oreilly/). C++ is now the one high-level language that is natively supported by the system vendor across Windows, Linux, Mac, iOS, Android, Windows Phone, XBox, and Playstation.
- seren 11y agoI agree about the universality of C++. I also agree you have to compare C++ + code analysis versus Rust regarding safety. However, my team is spending over 100k$ a year to get access to these tools. In the grand scheme of things, compared to the salary and other expenses, it is insignificant. But for a small team for a new project, it is probably easier and more cost-effective to use a language that is safe from the ground up, rather than relying on external vendors. (Most of these tools have a free option for FLOSS projects, but you might need to develop something closed source) I honestly don't know if this is something that can tip the balance, or if this is a "detail". Time will tell.
- jbandela1 11y agoTake a look at Herb Sutter's talk from CppCon 2015. The slides are here (https://github.com/CppCon/CppCon2015/blob/master/Keynotes/Writing%20Good%20C++14%20By%20Default/Writing%20Good%20C++14%20By%20Default%20-%20Herb%20Sutter%20-%20CppCon%202015.pdf https://github.com/CppCon/CppCon2015/blob/master/Keynotes/Wr...) and the video is here https://www.youtube.com/watch?v=hEx5DNLWGgA https://www.youtube.com/watch?v=hEx5DNLWGgA. Microsoft will be releasing the static analysis tool as a free cross-platform tool (and I think open-source IIRC). They shipped a preview for Visual Studio 2015 with Update 1, and are planning on shipping a cross-platform version soon. As tools like this become free and ubiquitous, it will greatly improve C++ code safety.
- _RPM 11y agoI believe C is the most important language to know. It's pretty low level and doesn't provide you with much, but learning what is taken for granted in higher level languages is valuable.
- tmaly 11y agostart with C. If you look at the programming language benchmarks, it is still one of the fastest. http://benchmarksgame.alioth.debian.org/ http://benchmarksgame.alioth.debian.org/ if you look at the C++ code on there, much of it is written in the style of C. If you can write newer code and do not have to maintain old code, C++ would be a good second. There are still tons of high paying jobs for C++. Some pay 400K+ in the NYC area
- elbows 11y agoFor your purposes I would recommend C. It's a very small language with very little abstraction, so it forces you to really understand pointers and memory layout. Rust is more complicated than C and it tends to insulate you from the low-level details. The way it combines low-level control with high-level abstractions is really interesting, but from an educational point of view I think you'd get more out of it after you understand C pretty well. C++ is a giant, sprawling mess. It can be very useful but I'm not sure what it will teach you other than how not to design a language. :)
- dpc_pw 11y agoC. Learning C is like being dropped on island and having to learn all the skills necessary to survive. After you master C, you go back to civilization and enjoy the simple life conveniences again, while being able to see through them at the real, crude and dangerous reality. After you learn C, go to Rust. Rust will just teach you more than C++.
- mbrodersen 11y agoLearn C. Then you ACTUALLY 95% understand how things work. If you want to understand 100% then learn Assembler. Assembler is surprisingly simple once you get it.
- sudeepj 11y agoI am a C++ developer and I would recommend Rust. By learning Rust my C++ development practices have improved when it comes to memory management.
- Arzh 11y agoI think C, it will help you learn all the rest. It also allows you to see how much some stuff like concatenating strings really cost in terms of performance. I think just knowing that as a fact will help you in writing in higher level languages.