HACKER Q&A
📣 abnry

Should I learn C/C++ or Rust as my first systems programming language?


I work as a data scientist in telecommunications. Mainly, I used python and matlab, but I want to extend my programming range to include a compiled, systems language because lots of digital signal processing is written on embedded devices.

To me, it seems Rust is so much better than C/C++ in many ways: lots of Python-like abstractions, rigid compile time safety checks... A modern language designed from scratch without a hodge podge of welded on features.

Rust could also turn into something big, by the looks of it, in the next 10 years.

So I have two questions: how much does it make sense for me, in my circumstance, to learn Rust as my first systems language, and the second question is how much, in general ignoring my circumstances, does it make sense to learn Rust first?


  👤 caditinpiscinam Accepted Answer ✓
I say learn Rust and C in parallel.

I'm learning Rust now after several false starts. Here's what I find challenging and interesting about Rust: most languages exist on a spectrum between faithfulness and abstraction, where they either represent the underlying hardware in an accurate way (like C), or they provide high level abstractions that allow you to simplify your mental model of how a computer works (like python).

Rust is interesting in that it uses abstractions which don't lead to a simpler mental model. There's no such thing as 'lifetimes' from the computer's perspective. And yet these abstractions, though somewhat artificial, can still shape your code in beneficial ways.

I think that learning Rust without having exposure to C would make it difficult to recognize which constraints that Rust imposes are based on actual limitations of the machine vs Rust's particular paradigm. So I say learn them both.


👤 sevensor
Don't lump C in with C++. They're very different languages. If anything, I'd lump C++ in with Rust. They're both big, complicated languages. If you're just looking to understand the C model of computing that underlies any Unix-like system, spend some time with C. Learn to write a linked list, experience a few segfaults, and then decide what kind of safety and abstraction you'd like in your systems language.

👤 petercooper
I think every developer should learn enough C to "get by" and at least to be able to read and reason about C code given there's so much of it out there, especially in the embedded world. But do you have to spend 5 years grinding out only C code? No.

Spend some time with C and learn the basics, do some experiments, and then learn Rust concurrently. It's not like you have to pick one or the other. You can be proficient with C while still becoming more fluent with Rust over time.


👤 steveklabnik
Hey there! Rust core team member and long-time C programmer here.

The short of it is, this is complicated, and it really depends on individual circumstance. You have given your circumstances, so I can help answer on that basis, but doesn't mean I agree it's the same for everyone.

There are two major ways of thinking here: Rust first, or C first. The advocates for Rust first will point to an easier onboarding story, a supportive community, a helpful compiler, and that you'll start off with good habits. The advocates for C first will point out that C is the latin of software development, and that you may not appreciate what Rust does for you without first experiencing the wild west of C.

Both of these have merits. I personally prefer Rust first. I of course, have a lot of bias.

I work in embedded Rust, and the thing is, the industry is still C based. Depending on which embedded devices, it may be your only option. So, I don't think there is any world in which you cannot learn C. Even though my codebases have no C in them at all, data sheets refer to C concepts, example code from vendors is all in C, blog posts and other helpful documents are generally in C.

So, absolutely, learn C to some degree.

Personally, what I would do in your situation is this: pick up a copy of K&R. Pick up a copy, either online for free, or in paper, "The Rust Programming Language." (I am a co-author. I don't make any money from the book; I recommend these two because they are generally considered the go-to book for each language.) Read them. See what speaks to you. Go from there. There is no reason you have to make a big choice up front and commit to it to all time. Try things. See what makes you go "I want to do more of that." And then move forward. Maybe you'll love C and never learn any more Rust. Maybe you'll like Rust and stick with it primarily. No way to tell until you give them both a shot.

(I actually strongly disagree with many of the ways that people characterize C, and even in this thread. C is not actually a small language, it is not super simple... but that doesn't mean it's not worth learning.)


👤 creata
Please, learn C. It's very fast to learn (it's harder to write good code in it, though) and it's pretty much the lowest common denominator that all languages and platforms try to interface well with. It's also much more popular than Rust is on embedded devices.

👤 jerf
I think you can go with your gut and learn Rust, because even if you discover that's a mistake and you need to switch to C or C++, there's probably going to be more transference than you think. Switching isn't free, but the knowledge gained on the "wrong" path will be valuable on its own, so it's not that big a deal.

Similarly, if you decide to go with C++ now, it's not a commitment if you later read about an awesome Rust DSP library or something.

It only becomes a commitment once you start writing real, production code in it.

It is also perfectly sensible to just set aside a week's spare time for each language and give them a try. You'll learn more real stuff from that than any amount of questions asked online about which is better.


👤 jeffreyrogers
C++ is used far more in industry and will continue to be used for a long time to come. Learning C++ will not hinder you at all and the newer C++ features make it fairly easy to use for someone coming from higher level languages.

I have only dabbled with Rust (I use C++ professionally), so I don't have a strong opinion about it. However, a lot of the positive reviews you hear about Rust are from amateurs who aren't using it in real products and a lot of the criticism you hear of C++ is from people who don't use it. Hopefully that helps you adjust some of what you hear to be a bit more grounded.


👤 yokaze
Depends on what you want to do. Either way, exposing yourself to more programming languages ideally with different styles and background should make it easier to familiarise yourself with others.

So, either choice is not wrong.

C and C++ are clearly different programming languages, so you are actually looking at three languages.

> Rust could also turn into something big, by the looks of it, in the next 10 years.

I wouldn't bet on that. 20 years ago, I heard Haskell and or Java is going to be huge. They are, C and C++ still are. Learn Rust by all means, probably you will be more quickly productive, and it gives you a wide range of choice of targets. That should be sufficient reasons to go that way.

> To me, it seems Rust is so much better than C/C++ in many ways: lots of Python-like abstractions, ...

Yes, but that is also an argument to go for either C or C++. You'll have to learn more. The active code-base in C and C++ is huge, and I don't see everything being rewritten in Go and Rust. Maybe you'll be less productive in churning out code, but it'll give you expertise to look and modify the existing code-base when necessary.

Not that you cannot do that when learning Rust.

In summary, I would go, with Rust, if you want to be quickly able to do your own stuff, C or C++ if you want to be able to work through existing code build "with a hodge podge of welded on features". The deciding factor between C and C++ again should be then, in what language is the code written you'll be looking at. I would say, (and others might disagree) kernel-code (OS kernel, that is), Microcontroller, low level stuff more likely C. C++ you'll find more likely in application code, numeric libraries, etc..


👤 snarfy
Learn C. You will always need to know it. The K&R book is not a very big book.

That said, the elephant in the room is the toolchain. With Rust you use cargo. With C you use ... a hodgepodge of technologies glued together with duct tape. While learning C, you'll also learn about make, cmake, autotools, ninja, bash scripting, etc.

C is easy. It's all that other crap that makes it more challenging.


👤 jeff-davis
I see those as three options: C, C++, and Rust.

I'd suggest learning C. It's the simplest language of the three, and it's the lingua franca of systems programming. You will have tons of resources and examples to work from. And you won't get stuck/frustrated over type system or lifetime issues. You'll always be making progress with C even if it's buggy.

While learning C, I highly recommend that you dabble in Rust. Rust has introduced important concepts to programming that will not go away, and just does a lot of things really well, including C integration. You also might appreciate the really easy cross compilation system for embedded development.


👤 nemetroid
C/C++ is not a thing: they are separate and very different languages.

Especially if you're interested in embedded applications (and probably otherwise as well), I would suggest learning C to start with. Whether to go for Rust or C++ after that is up to you.


👤 baq
Rust will force you into correctly handling the major footgun of C and C++ - ownership of memory. If you decide that you want to learn C++ later, it'll only take a few dozen segfaults instead of few hundred to get up to speed ('would something like this compile in rust?' is a helpful question to ask if possible)

👤 flohofwoe
IMHO: Learn both but start with Rust. Rust forces you to think about memory management topics (memory lifetimes and ownership) which you will also need to know about in C++, but in C++ you are entirely on your own so it's easier to "slip into" bad memory management practices (which you would need to unlearn again when moving from C++ to Rust).

You should also include C in the mix (very different from C++(!!) that's why "C/C++" is a bit shunned upon by some people), because Rust or C++ are often overkill. If you're tackling Rust and C++ anyway (which is essentially a lifetime task), learning C on the side is literally a "weekend project" ;)

Just remember that C and C++ are not as similar as many people believe, they are different languages with different goals and a different philosophy.


👤 monstrado
There's a lot of great resources out there for learning both Rust and C/C++. That being said, I feel like if nothing else, Rust serves as a great way to teach you the importance of memory safety. This is a skill that translates very well if/when you want to learn C/C++, as well.

If you have memory safety issues in Rust, it just won't compile (with extremely to-the-point compile errors). In C/C++, you might have to debug for a while (especially if you're new) as to why your app is inexplicably misbehaving.


👤 agentultra
I'd say it depends a lot on what you value and where you'd like to spend your time.

Would you consider yourself an early adopter type who's more happy working on the bleeding edge? Rust is great but it's not a mainstream language yet and working with late adopters will be difficult. There are fewer project and job opportunities in Rust. You may have to be comfortable with writing your own libraries and tooling.

If you're more of a late-adopter type you probably value stability and maturity of the tools you rely on and perhaps put more emphasis on solving your domain problems rather than language tooling and tech problems.

The other factor to consider is what your goals are. If the incumbents in telecommunications have built a large ecosystem of libraries and tooling in C/C++ you're going to be working in a small niche writing things in Rust. Do you want to carve your own ecosystem in the space or would you rather spend time improving the status quo and moving ahead with the rest of the pack?

There are no wrong answers! It all depends on what you value more. They're all fine languages and tools. If you lean towards Rust simply because you're happier working in it then go for it. If you're not being paid to work on these projects then happiness is definitely a strong indicator you should be using Rust.

Happy hacking!


👤 ufmace
I guess it depends on what kind of tools you see yourself building with a compiled systems language.

I feel like I'd prefer Rust, due to being simpler and more straightforward. It doesn't have decades of history, so there's less of a situation of having a bunch of legacy ways to do things with various footguns. Cargo makes it easy to pull in crates and build things with them. Some of it's parts, like Serde, are really slick. Others, like async support, are still a little tricky.

On the other hand, there's no denying that C++ has a massive library of integrations with all sorts of things, and supports way more hardware, due to it's immensely long history. It's the preferred way to interact with most of the native GUI libraries out there. There's a zillion libraries you can connect to your C++ code. It's probably a little more complex than the best Rust integrations, but better a well-tested natively supported integration than trying to build a new Rust integration around it, or rely on a half-finished open-source project that nobody cares enough about to support.

If any of those C++ reasons sound like something important to you or that you might want to work with in the future, then go with C++.


👤 ncmncm
If you ask HN, HN will almost always tell you to learn Rust.

But HN is its own echo chamber. Rust is practically unheard of outside the enclave. If you learn Rust, you will be obliged, in short order, to learn other languages that are actually useful in your target area.

So, find out what languages are used there, and learn those. The only bad mistake would be to start with C.

That said, it is not a mistake to learn Rust. Just don't expect it to be usable at work.


👤 sumanthvepa
I will go against the grain and recommend that you learn C++. Yes. It's a complex language, but it is extraordinarily powerful and meant to be used when nothing else will do. It is not a suitable language for novices to write production quality code in. But in the hands of an expert, it can do some amazing things. Rust is nice, but its performance still doesn't come anywhere close to C++ for many tasks. When you need to build extremely high performance systems that are also very complex (think CAD software, simulation etc.,) C++ is simply unbeatable. Also, once you've mastered C++, you will find Rust fairly easy to learn.

👤 kbumsik
I think learning a language is not the point, but learning underlying system (OS) is.

What you want to learn (especially in embedded world) is how various Linux/POSIX APIs work, not language features.

So either choice is good as long as you learn to use them, but I personally recommend C because C is the first class language for Linux APIs e.g. they are exposed directly via #include > or #include >.

As others recommend, you can learn C and Rust at the same time though.


👤 richardanaya
Here's a quick way to figure out if Rust is for you: https://tourofrust.com/

👤 stmw
I think learning Rust first - and then possibly C - is a better plan for your background of python and matlab. I think it can be difficult to appreciate C when coming from the higher-level languages, and so while it may be easy to get along with it, it won't really change how you think about code... My opinion would be different if you had done no programming before, then I'd say start with C, then Rust.

👤 Dowwie
Learning Rust is a lot of fun. There's a large community of people who enjoy using it and helping others solve their problems on Discord, Reddit, and Discourse. Experienced embedded developers are saying really positive things about Rust for their work, with the exception that the open source ecosystem remains in its infancy. I'm noticing embedded Rust job listings sprouting up in a lot of industries, so I think we have much to be optimistic about at this point. Also, teams such as those at Ferrous systems are focusing on long-term viability of Rust for embedded by investing in the ecosystem and creating onboarding pathways: https://ferrous-systems.com/blog/

Even if you don't wind up doing embedded work, you can cffi your python to Rust libraries for performance optimizations. You probably won't be writing optimized Rust for a while, so don't plan for quick wins with Rust extensions until you're several months into working with Rust full time.


👤 blub
In your circumstances I'd skip Rust altogether and focus on what the industry's using and what your colleagues are using. This will most likely be C or C++. If you go for C++, you can also use it in other domains, such as data science.

Rust is something you learn if you want to get a job doing Rust or for your general knowledge, not if you want to solve a problem or understand an existing domain.


👤 cfcosta
I would say give a nice look at C and C++, you are probably going to appreciate Rust a lot more if you know where your foot can be shot by it.

Learning just C/C++ is also completely fine, so don't think it is a waste of time or anything like that, both are not going to go anywhere and having them on your toolbelt will help even if you do decide to go with Rust in the future.


👤 josh2600
We're a fully Rust shop now (we write code for secure enclaves up to and including implementing a custom malloc from scratch). I actually don't see any reason to learn C anymore unless you are interfacing with older systems or doing stuff where you need to drop out of Rust's guardrails (if you're new to systems programming you're gonna wanna avoid unsafe code as much as possible).

It's just a lot harder to write broken programs because of how screamy the compiler is in Rust. You will spend more time getting your code to compile but it will have fewer errors (and be multi-threaded+memory safe by default).

I think most production software that is written de novo today will be in Rust over C/C++. It's just not comparable in my opinion. Like, when we implement stuff we can have logic errors but eliminating the entire class of buffer/array/pointer failures is extremely useful.


👤 sbeckeriv
I have used Ruby and yes Rails for work for over 10 years. I did learn c++ in school but never use it professionally. Like you I see a lot of what I like in Ruby in Rust. I have been using it "amateurishly" for the last 3 years. I it has made me think about my Ruby code differently for the better. Could C/C++ do the same thing? I am unsure. I hope to one day use Rust as a professional but until then it will be my go to for fun projects and serve as a tool for learning. I expect Rust to extent beyond the statement of "systems language" at some point. I just wrote a search tool based on my browser history using 99% Rust (Actix server, Tantivy search and Yew wasm frontend). Not having to write much javascript for a full stack project was refreshing.

👤 business007
Before all, I'd spend a while learning C, because C is kind of lingua-franca so it will be useful to understand alot of programming languages, that are part of C-family, including C++, Rust and D. Also Rust end C++, I would consider learning D.

👤 pelliphant
I work a lot with embedded devices (arm cortex-m chips mostly), and if you download the datasheets for some chip that you think that you might be using, I would guess that the only code mentioned in it are going to be in assembler or C.

Also, if you have a chip that you think you might be working on, check out the development tools from the chip manufacturer, it will probably be made for C.

Learning to use a chip is much easier if you have a library of examples written by the chip-maker for that specific chip.

For those reasons I would recomend C.


👤 lsllc
Rust. For sure, otherwise stick with C. Having programmed in C++ for a long time (but no more!), I think it has too much baggage (compiler support / versions / platforms etc) and the ecosystem isn't as good as Rust's. C is just C and you need to know it from a first-principals point of view, but it's terribly unsafe compared to Rust (kind of like driving in a 60's convertible with no seatbelts or ABS).

👤 crazypython
I think the Rust hype is starting to die. Take a look at D Language. It was created by Walter Bright (the first person to single-handedly make a C++ compiler, Zortech C++) and Andrei Alexandrescu (former C++ committee member and author of Modern C++ Design).

Also, for number crunching- since you're a data scientist– Julia and Numba might be better choices, as they crunch numbers efficiently.


👤 augustk
Another interesting systems programming language is the Pascal descendant Oberon which is (way) simpler than all three languages mentioned:

https://www.miasap.se/obnc/oberon-report.html


👤 andijcr
You seem pretty set in your choice already, just looking for confirmation. what's stopping you?

👤 jameswatson333
Rust's compilers are built in C++. They are not on the same playing field yet. If you want to make a comparison, it would be C and Rust. Both are excellent system programming languages, but I recommend Rust for its forced memory-safe syntax.

👤 nikivi
Rust has a nice up-to-date book and more rich community than C++. Plus better tooling.

👤 aazaa
Given that you already use Python, have you considered writing C extensions as a way to take advantage of what you already know to learn something new (C language)?

You can do the same thing in Rust, but it's a bit more work.


👤 scott_meyer
Neither. Learn Scheme.

Structure and Interpretation of Computer Programs is still the best single book on computer programming: the most important concepts (closures, continuations, macros, transformations,...) for the least expense in complexity.

To what you learn from SICP, rust and C++, add just one thing: how to exploit a physical stack efficiently. Scheme->C++/rust will be easy. C++/rust->Scheme can still be quite difficult depending on how distracted you got by the complexity.

As a practical matter, most system software is written in C. Being able to read the Unix kernel has been valuable for nearly 40 years. You'd be surprised what one can accomplish with just functional decomposition.


👤 3np
My 5c:

You should really start with C as it gives you a solid foundation both of how things work under the hood, and you'll be likely to have to dive into C from time to time. Apart from K&R, Hacking: The art of Exploitation 2e[0] is a really great book to grok C.

But you can safely skip C++. Rust is a C++ killer IMO.

[0]: https://en.wikipedia.org/wiki/Hacking:_The_Art_of_Exploitati...


👤 ldargin
It sounds like you want in increase your range. Spending a few weeks learning basic C would provide a good starting point. Be sure you understand pointers, allocating memory, stack vs. heap, etc. From there you can launch off to C++, Rust, maybe Julia, etc.

👤 fmakunbound
Perhaps define "systems programming language".

👤 juststeve
rust, because it has cargo.