r/rust • • 8h ago

🙋 seeking help & advice Should I learn C++ or Rust first?

Hi everyone! I'm a teenager and I'm really into FOSS software and Linux. Up until now, I've only been a user, so I'd love to finally step into the 'kitchen' and start building things myself. Aside from some basic Linux shell scripting, this will be the very first programming language I'll learn, so I'm trying to pick the right starting point. I've heard that Rust is the future of both Linux and FOSS—is that really true, or would something else be better for me? Could you please help me make up my mind? Thank you!

33 Upvotes

50 comments sorted by

52

u/Bagelsarenakeddonuts 8h ago

I think you will learn better habits from rust, and its quickly overtaking c++ for new projects. But there is a much larger existing codebase of c++.

I think if you have the drive, go ahead and try with rust. If you can stick it, you will build really good habits to start, and you can easily learn other languages after. If you find it overwhelming, don't give up coding entirely, there are other easier languages to pivot to and you can try those too.

3

u/Zealousideal_Rise716 7h ago

A really helpful answer. I come from an industrial automation background where all our RTOS's and languages are highly deterministic and memory safety is paramount. Rust is literally the first language outside of my domain that has 'clicked' for me.

Having said that there is a huge amount of excellent C++ out there and I doubt any new programmer can afford not to be fluent in it as well.

3

u/ThaliqueMuse 5h ago

i've been thinking about starting with rust for the same reason, good habits from day one sound worth the effort

2

u/Bagelsarenakeddonuts 5h ago

Yeah, the "hard" part is understanding why things have to be done a particular way. And that has to be done with or without the good language, its basically the same principle of learn C the hard way.

Think of it like learning any skill, instrument, sport, etc. Is it easier to hack at it and then relearn later, or learn it properly the first time?

But if its hack at it or give up entirely, then go hack at it haha.

1

u/WittyFeral 5h ago

rust first sounds smart but if it gets overwhelming think i'd need someone patient to walk me through it

1

u/angelwishh 5h ago

rust sounds like the move for building good habits early, you sound like you've been deep in it already lol

42

u/KingMagnaRool 7h ago • Bravo

I wouldn't recommend either. C++ is an enormous language with a billion different ways to do the same thing. Knowing which ways are "correct" in modern C++ is a difficult thing to pick up as a newcomer, and there are a ton of outdated resources to make things even more confusing. Meanwhile, while Rust is far more restrictive on what you're allowed to do with it... it's far more restrictive on what you're allowed to be doing it, and you will be fiercely fighting it at every turn as a beginner.

I would seriously recommend learning C before Rust at the very least. C is a much simpler language than C++, which makes it much easier to figure out how you're supposed to do things in a general sense. Its basic operations are very close to Assembly relatively speaking, so if you end up learning that to get a better sense of the instructions a computer is running under the hood, it'll be a slightly easier transition. You'll also be able to shoot yourself in the foot with segfaults, and hopefully gain an appreciation for what both Rust and modern C++ constructs are trying to solve.

10

u/dnew 7h ago

I'm going to second this. Learning C at least to the point of writing say a 100-line program is going to give you great bang for your buck. At least read the K&R C book and try to understand it.

The problem with C++ vs C is all the 101 legacy reasons why C++ sucks. C has the same problems, but they're obvious right on the surface and the language is simple enough you know what you did wrong.

6

u/Puny-Earthling 7h ago

Why does everyone think C is simpler than Rust? C is only simple if you're doing simple stuff with it. If you mean less features and a compiler that will go "Yeah that terrible code looks fine lets fucking go cowboy! YEEHAW!" then yea, fine C is simpler.

Rust is multi-threaded implicitly and automatically guards the data in mutex and releases the threads, and refuses to compile code that would share threads unsafely. Also automatically cleans up memory, whilst C you have to join and detach each thread and unlock every mutex on every path and if you're not doing a "free" on every "malloc" or you "free" too early, or twice you create leaks and security holes.

I guess C is "simple" since it has such a small core library that you can basically rote learn it into your memory in a few days, but the rules aren't visible or intuitive at all.

12

u/KingMagnaRool 7h ago edited 6h ago

C is simple exactly in the ways you describe. Clearly, it is harder and more error prone to do complex things with it. Though, for a beginner, that's pretty much the point. I guarantee you someone trying to learn a programming language, or how a computer works internally, for the first time cares about any of the features you mentioned which Rust makes easier. A beginner is not writing critical software, and they shouldn't be fighting the compiler at every turn starting out for benefits they likely won't use yet.

C can be unintuitive starting out, especially its pointer semantics, so I'll give you that. A language like Python or Java gives much more intuitive error messages, and I think they're much better first languages. However, nothing currently fulfills what C can do as a first systems language for the purpose of learning.

Edit: You can't tell me that Assembly isn't, at its core, simple. For a basic RiSC, all you do is load, store, and do arithmetic, and the core x86 instructions aren't that far off. Its difficulty stems precisely from its primitivity, and you'd be out of your mind to say Assembly is not worth learning at all. C vs Rust is a less extreme version of this argument.

2

u/Puny-Earthling 6h ago edited 5h ago

I don't entirely disagree with you on a "first systems language", but I also just personally *Don't think it's worthwhile to learn how to use C effectively when most of that learning is effectively moot once you move over to a language like Rust.

My first languages were Java and then C, which was a nightmare of a learning experience and if I were fresh learning from scratch tomorrow, I'd be learning Typescript, Rust and Python (or Ruby). While C and C++ are the closer analogues to Rust, I'd encourage people towards Go before either of them, as it still enforces about half of the concepts that Rust enforces albeit only by breadth, not depth.

Edit: Don't think*

0

u/KingMagnaRool 6h ago

I do forget about Go quite a bit, don't I? I can see the Go to Rust pipeline.

I'm not really trying to argue that being a good C programmer would make a good Rust programmer. Something like Ocaml probably makes for an easier transition, which it did for me (though I would never argue it's a good first language). What learning C should do is teach you generally what a computer can do at a low level. Of course, this requires the learner to go out and find things to learn: some examples being setting up an embedded project from scratch to learn how memory is organized on an embedded system from the ground up, or manually flipping bits in peripheral registers, or doing Unix system call stuff, or experimenting with binary exploitation. However, there really is no substitute for C in these spaces when it comes to learning from the ground up.

1

u/El_RoviSoft 2h ago

At this point I think Pascal was a right choice from teacher’s perspective back in a school… Good middle ground between C and C++/Rust.

6

u/kamikamen 7h ago

Whichever one you want, but Rust.

6

u/Joe-Arizona 7h ago

Do the Harvard CS50 course on YouTube, learn C then move on to Rust.

I’m glad I learned C++ but it is a gigantic language with many ways of doing the same thing. Read up on the basics of it on the side but I wouldn’t focus on it too much.

4

u/elitegreg88 5h ago

I know both C++ and Rust. Do yourself a favor and learn software engineering instead. Learn about building scalable software, about keeping data safe and secure, about performance, and about designing tests that prove software works. AI writes great code these days for most applications and you won't beat it in a bidding war unless you will work for bananas. I'm fairly confident the next major computer language will be designed to be optimal for AI writers.

3

u/shizzy0 4h ago

I only truly understood C++’s dream when I finally learned Rust but I’d say learn C first. C is tiny. C++ is huge. Rust is medium.

0

u/Minute-Store7277 3h ago

Why not do Zig over C?

3

u/shizzy0 2h ago

Zig is a different thing. Sure it’s a better C but it’s more complicated too.

1

u/ComedianMuted5486 2h ago

Zig has little in the way of learning resources, and a lot of learning resources it does have are out of date because the language is still unstable. A blog post from 3 years ago might not compile anymore. Bad choice to try to learn about as a first language.

5

u/Puzzled-Extent7817 5h ago

C, then rust

7

u/jesseschalken 6h ago

Rust is a fine first language. It’s also a good “last” language, it’s so versatile that you don’t need other languages very much. Although Python is still convenient for scripting and data science.

I definitely wouldn’t learn C++ unless there is a specific C++ codebase you want to work on.

3

u/nhermosilla14 7h ago

Start with Rust, then learn modern C++ (which borrows a lot from the same ideas, no pun intended). Rust feels much more restrictive, but it's not that terrible once you get used to it. C++ is like a very long tv series, one where the main characters from the initial seasons got replace several times already, so you will find a lot of seemingly contradictory stuff on it that doesn't apply to the current state of the art.

3

u/shonks1 5h ago

What I always recommend people for starting for starting with your “first programming language”:

  1. Learn Python first. Build a snake game or something. Python has a simple syntax and a large library and a number of features that make it “easier” to pick up. This will get you to internalize a lot of the basics. Python is also a good language to have around for quick prototyping. Despite preferring to work in Rust, any interview questions or prototype ideas I’ll whip up in Python. And I still prefer Python for some things.
  2. Learn C next. This will be much closer to the machine then Python, including manual memory management. The K&R book readings and exercises should be enough here.
  3. Then learn Rust. I never learned C++ outside of some basics, and I’ve landed myself a job using Rust. A lot of places are switching over to Rust, and you’ll just have a more fun time in Rust than C++. Especially if you’re a teenager, the most important thing is to have fun with it.

1

u/scadoshi 7h ago

I would highly recommend building your projects in Rust while having C++ or C scratch projects tandem to them.

Like what I see others recommending in this thread, Rust will teach you really good habits and eliminate a whole category of bugs, BUT it's helpful to know why it does what it does.

That's where the C++ or C work comes in. Trial parts in freer languages to get an idea of how memory management by hand is done and where it could break. Then land in Rust resulting in more knowledge and more solid projects

1

u/Unhappy-Salary8171 7h ago

That's a great question. Go with Rust if you want to learn best practices in programming. You could say it gives you less "freedom," but that's exactly what will make you more aware of your code and who's using it and when.

Use C++ if you want to learn the hard way. It’s always been said that C++ gives you absolute control, and that’s because it assumes that every step you take is carefully considered and that you know exactly what you’re doing—but more often than we realize, that’s not the case.

With C++, you’ll feel like you’re moving faster—that everything is smoother and quicker—but at any moment you might crash, and your code might have a memory leak or a segmentation fault without you knowing where it came from. With Rust, you’ll go a bit slower, but because of the way it’s designed, your code will be much cleaner and safer.

1

u/Expensive_Bowler_128 6h ago

I would like to second another commenter in saying learn C first, then Rust. C++ has a lot of features and a lot of ways to solve the same problem. Learning how to do it “the hard way” in C will provide a good foundation for when you get into Rust to understand what problems Rust is trying to solve. It is hard to appreciate Rust if you have never experienced a seg fault or worked with raw pointers.

If you ever choose to learn C++ down the road, C will be useful as any valid C program is a valid C++ program - C++ simply builds on the language

1

u/UnlikelyFuel5610 5h ago

C++17 first

1

u/Formal-Grass-3173 4h ago

I learned C++ first then Rust, but I mainly work with Rust now. Language barrier is not a thing anymore as you can code with ai, so you can perfect yourself on both at the same time.

1

u/candyFawny 4h ago

rust's habits sound worth the grind

1

u/kittenheart 3h ago

C++ first then you will appreciate rust.

1

u/Only_ITR_No_Bakwas 3h ago

Unpopular opinion lear c or python first

1

u/goomyman 3h ago

There is no reason to create a c++ project anymore. The disadvantages of Rust were its difficulty- which AI addresses.

I would learn RUST. It’s going to be in demand since AI is writing everything they will want a human in the loop to review things.

Honestly though I would learn C until you understand the basics then RUST.

1

u/thisisnotmynicknam 3h ago

Start with C, then you learn a most high leel language.

1

u/Key-Stay1118 3h ago

The method you use to learn is what you need to master, not the subject.

Ask ChatGPT to organize the chapters for you. It is very helpful than bunch of cheap shit Udemy or repeatedly monkey sees what monkeys do on Coursera nowaday.

All other comments above are pretty much bias and keep repeating what you might have already known.

Don’t be on Rust side nor C’es side. These fools will just keep arguing and bringing more out of topics in regardless of your level.

Print each chapter of your currently ebook one by one and upload them on ChatGPT, use it for your own workbook and unique learning path.

Your time, your choice. Don’t fall for the “Python is for beginner” crap.

Everyone who passes GED can learn pretty much any modern programming language.

1

u/Aghoradas 3h ago

Don't listen to ANYONE about this question unless they say both, or they say whichever you want. Everybody else has an agenda, which you have already seen from the first bit of responses you've gotten. Just pick one, whichever, and start coding. You can always learn another language. Programming basics are universal.

1

u/Technical_Ideal_5439 2h ago

Dont learn C++.

C then Rust. If you really want to to be a solid programmer you need a solid full featured language to be your first and best and Rust can fulfill it. Admittedly C++ was mine but latest and greatest C++ I think has lost its way.

Though personally I would learn golang and see if you can contribute to any CNCF projects. And stay away from javascript as your first solid language.

And Rust is flavour of the month, because it maybe technically superior does not mean it is the future. The reason languages do well is normally far from their technical superiority.

1

u/ComedianMuted5486 2h ago

There's a lot of recommendations to learn a bit of C first, and in the abstract I agree. It will help you gain an appreciation for what Rust provides and what issues it prevents, which will help the learning curve with Rust later (when you may sometimes wonder why it's being restrictive). Python is also a really good language for picking up programming as a beginner (from the complete opposite direction as C)

But the most important thing is to stay motivated, and in that sense, don't pursue "learning the right way ™" to the detriment of actually learning. If your motivation is to learn FOSS and Linux then learning a bit of all of it is great, if your motivation is primarily Rust then don't feel like you have to do the other stuff. You can just learn Rust if you want.

1

u/DanKegel 2h ago

I agree with learning Rust over C++ for systems programming; anything that needs to be right and fast should be in Rust.

But you may as well also learn some Go; it's easy, and some jobs might prefer it.

1

u/bogoris76 2h ago

If you never programmed learn python first. Reasons are pragmatic: it's simple to starty, easy to run, good IDE support -- e.g for debugging. Once you are able to build some applications step up to something closer to the metal.

1

u/meowsqueak 1h ago

You’ll never master C++ unless you’re prepared to put in decades of study. And by then it’ll have got 2-3x worse anyway.

Go with Rust, it’s harder at first, but once you’re over the hump you will have a decent shot at becoming an expert, and it’s also a more friendly and respectful community.

You’ll also learn more if you ask questions about Rust design because it’s been designed to meet real-world problems, and not by a committee that decides what is least likely to offend existing developers or break everything in the world.

1

u/MyFistsAreMyMoney 1h ago

Rust. C++ is a mess and you can do several things wrong

1

u/yahbluez 40m ago

rust, it will help you nothing to learn c++ if you like to understand rust. It will make your way to rust harder not easier.

1

u/dariusbiggs 39m ago

C++, so you can learn why rust exists and why people use it

1

u/Weak_Painting_8156 26m ago

Learn markdown, the rest is obsolete. 🤷

1

u/creeper6530 16m ago

You'll learn good habits in Rust you can then carry over to C++.

Learn C first tho.

1

u/EmperorOfCanada 1h ago

The question is why?

I have been programming for over 3 decades. That is 3 decades of no AI.

I've primarily used C++, but over that time, I have had to solve a massive number of problems, and while C++ was a good solution to many of them, it often was not, and thus, I learned some new language.

What I've learned is a few things which go far beyond C++ or any individual language. I've learned that tech debt is what kills good projects. I've learned that communication skills are insanely important. If you don't communicate well, and end up building the wrong thing, it does not matter how well you built it.

I've learned that workflow is often what makes the difference between a nightmare project and one which is pretty smooth.

But, I learned all these lessons from two sources. The hard painful way, or sitting around the development campfire and having other people tell me their painful stories, and the useful discoveries they made while suffering.

With AI, all the traditional suffering is gone. The problem for someone like you is that AI is better than you are right now. Way better. What you want to do is to somehow bridge the gap to where you are better than it as a common sense human being. This takes experience to be able to call BS on what it poops out, as it will poop it out with great confidence.

To badly answer your question, rust is an excellent language for the present, the future, and for working with AI. I could spend the next 10 hours writing this comment about how I love it and it has changed my life.

Yet, I'm going to make a different recommendation. Don't learn C++ or rust, or even python.

Learn C and Assembly. Don't learn to get AI to do C and ASM for you, but actually make programs, by hand, from scratch, which do things.

There is a game library called raylib. It is about as clean a library as I've seen in my life. Make games in C with that. Make pacman, make space invaders, start with pong.

But, then push it hard. Make multi player networked pong, make sure it is using threads like you get $1000 for every thread you use. Not because it makes for a better pong, but because threads are a nightmare to get right.

Make a server which hosts games, make them on multiple platforms.

Use AI as a textbook. Don't copy and paste anything from it.

This way you can become a developer, and as a developer, you will be far better able to wield AI programming tools, as that is what they are. Tools. They aren't developers.

Maybe you won't use C in your future, but it will give you a brutally hard introduction to what the computer is doing under the covers. Then, when you probably end up using rust, you will find it smooth sailing, and have the confidence to understand when the AI is feeding you poo.

0

u/Middlewarian 7h ago

I think languages that embrace on-line code generation have an advantage over those that don't. I'm biased though, as I'm building an on-line C++ code generator. However, I acknowledge that Rust has some strengths and hope to 'rustify" my software.