r/learnprogramming • • 2h ago

Languages What should i consider when choosing between C++ and Rust as my main programming language

Currently i only really plan on programming simple tools for myself but in the future i also need to learn programming for engineering. What should i consider when choosing between the two, what are some important considerations and what should i be aware of?

2 Upvotes

15 comments sorted by

3

u/Longjumping-Boss5708 2h ago

For game development, C++ has a longer history and more established tooling. Rust offers memory safety guarantees which can reduce certain classes of bugs during development. It depends on whether you prioritize existing ecosystem support or modern safety features.

1

u/WillingPirate3009 2h ago

Does Rust for game development makes sense even if there were a mature ecosystem for it like C++?

2

u/edwbuck 1h ago

Depends on how much of the ecosystem you want to rebuild and debug.

And keep in mind that building with Rust provides no extra security unless you redesign for Rust borrow checking. The moment you use the unsafe keyword, you have all the same issues you had with C++. Finally, C++ has tons of memory leak detectors (valgrind is just the tip of the iceberg) and the other problems outside of ownership are easily handled by not doing raw pointer math (something that the C++ compiler will already warn about).

Rust's protection is real, but optional, frequently discarded, and requires one to redesign the solution to use it. It's not a simple "do I use X or Y" because the benefits are not clear cut.

•

u/spinwizard69 6m ago

One driver to favor C++ is the massive amount of existing code. As for a lot of the horror stories with respect to C++, are the result of early C++ standards. Modern C++ has improved massively. As for Rust like my other posts I think it is too little too late. AI is the future and its rapid improvement is going to run many languages into the ground.

2

u/the_MatchaGaucho 2h ago

If you're just building simple tools for yourself right now, Rust's compiler will act like a pedantic roommate who won't let you leave dishes in the sink. C++ will let you do whatever you want and then segfault three hours later when you forgot a semicolon in your dreams.

Engineering later on probably means interfacing with a ton of existing C/C++ libraries and hardware SDKs, so that might tip the scales unless you enjoy writing FFI bindings for fun.

2

u/Kseniya_ns 2h ago

Being employed

2

u/BrannyBee 1h ago

The most important consideration at this phase is to waste zero time choosing the correct language or tech. I'm serious, literally imagine whatever you want to make one day the most, then google "best programming language to make [insert thing you want to make]"

Stop researching there. Nothing about speed, dev features, opinions professionals have (and they all have them and will die defneding those opinions) matter. Whatever the first real link suggests first, thats the language. Stop researching any other languages or even the benefits of that specific language there. Hell, I dont care if there's 10 languages listed on that first google result, literally pick the one with the coolest logo for all I care and that is better than doing what you and every other beginner does spending so much time choosing the perfect stack.

Then you spend an absurd amount of time mastering that one language, beginner tutorials for the basics, making as many projects as you can along the way, and relearning the basics over and over again as you continue learning new stuff. Then you keep learning the basics more and more after you've learned the basics.

Use that language for everything you can, if its a "bad" language for making websites, do it anyway. If its a pain in the ass to automate stuff, do it anyway. Any general purpose language you'll see recommended can be used to make most things somehow with a little cleverness or just being persistent. Fucking Balatro made a bazillion dollars and was created with Lua of all things, which might not mean anything to you, but to many devs is absolutely fucking insane and I would do anything to forget the fact that thats even possible. Don't make any excuses about how you need to restart on a new language because [language i chose] isn't the perfect on for [next project]. A psychopath made a bazillion dollars making a game with Lua, you're just looking for an easy way out, dont do that when you can get a better mastery of whatever language you chose.

Then guess what. You spend a few years mastering that single language, and you now know enough to determine that the thing you want to build truly would be better using a different language, and you understand why, the oppurtunity cost of using [language you don't know] vs [language you mastered], and genuinely have enough knowledge of the field and how programming works to make that call.

You didnt waste any time at all. It took you 2 years to learn a single programming language enough ti be comfortable with it as if you were typing in english, sure. But if you truly mastered that first language and focussed on it obsessively, it will take you a month max to get a workable knowledge of whatever new language you feel is necessary. Im not kidding. A lot of concepts are transferable, and even when there isn't a one-to-one comparison between two features of a language, knowledge of one language will make it easier to understand what the new language you are learning has or doesnt have compared to your first language. Hell, some languages are similar enough to where you can read them enough to understand quite a bit even if you cant understand everything. Kinda like how if you can read Italian, theres a bunch of Spanish sentences that you can understand even though you dont know spanish.

Coding is the easiest part of programming, and its easy cause you do a ton of reps and practice. Those who have learned a language or two very indepth have the ability and knowledge to learn new languages extremely quickly. In fact, in interviews for programming jobs, I dont think ive EVER been told what language to use in order to solve problems during a technical problem... I've literally interviewed for a C# contract, received and offer, and never had touched C# not even during the interview. Its just a known fact that if you master a language, learning another on the job will happen quickly, quick enough that companies will hire someone to learn on the job and be able to pick up a language in a few months.

You specifically are asking what is important to consider when choosing a language, so here it is. I say this with zero irony at all, and am absolutely serious, you already know too much and shouldn't waste anymore time at all learning anything about languages. You have a choice to join like 80% of beginners who learn 30 different languages and switch to a new favorite every month, and never really get good at reading or writing code, or just starting. If you start now, even choosing the "wrong" language literally puts you leagues ahead of anyone trying to weigh all options befire they commit to the optimal choice for a very specific task without even having the baseline fundamentals to understand what the differences between languages even truly means in practice. Meanwhile there's some psycho making the next indie dev hit that will make a billion dollars with some stupid language literally no one even knew could be used to make games...

1

u/captain150 2h ago

I mostly taught myself (badly) c++ to run MPI calculations for my masters thesis. C++ has decades of history and about 5-10 ways to do everything, most of which will be "suboptimal". I'm a weirdo and actually enjoyed the problem solving that comes with debugging, but if you aren't me then c++ will give you nightmares.

On the other hand having learned c++, I was able to pick up easier languages like python in no time. I can't speak to rust, but the ecosystem for c++ is so massive that learning it won't be for naught.

But manual programming is already mostly dead for obvious reasons (AI). I asked Claude to re-write my 5000 lines of shitty code I wrote for my thesis and a couple hours later it was done, and fixed some latent errors/bugs I had. I'm glad AI wasn't a thing during my grad school since it would've been too tempting.

•

u/spinwizard69 3m ago

This is the thing I try to stress, the industry is changing rapidly with AI. Also I might suggest that modern C++ and a little upfront formal education leads to far better C++ code.

1

u/Delicious_Bed_4410 1h ago

Since you said simple tools for yourself first, I'd pick based on what you'll build in the next few months, not the long term. Check which one has a library for the first small thing you want to make, and which one you're more likely to keep opening on a weekend. For engineering later, look at what the tools in your field already use, since being able to read and reuse that code matters more than the language itself.

1

u/povlhp 1h ago

Libraries is often a main driver

1

u/ro_ok 1h ago

Many other languages are based on C and C++, specifically trying to address issues with those 2 languages. Rust is based on trying to fix memory management of C without using a garbage collector.

If you learn C++ it will make it easier to learn other languages and understand features of those languages. If you learn Rust it will make it easier to write Rust. I love Rust, but learning C++ after I'd learned Perl, Java, and Python was incredibly eye opening and I wished I'd started with C++.

•

u/spinwizard69 11m ago

When going about learning CS you don't want to focus on any language at the beginning, you should be focused on learning the concepts. Thus my suggestion is to find a good CS program and follow that, any decent CS program will expose you to several languages over time. Ideally the program will start out with C++, if not I really question what the goal of the program is.

Done well you will be able to adapt to any language in the future, which is good because to some extent you need be exposed to platform languages. Frankly a college program will not focus on a specific language like C++ beyond what is required to get concepts across. They may have an elective class to dive into a language to a greater extent. Done well though the college will expose you to at least 3 languages by graduation and ideally a required assembly class.

AS for your future AI is going to be a significant factor in the future and you will not be using a traditional programming language in a few years. However for the near future you need to put in effort to learn a language well, which really takes years. It probably is not a bad idea to focus on C++ a bit due to its wide usage. Personally I think Rust is a waste of time because it is too late to the industry, AI will make it an after thought.

Here is the big problem, you didn't mention what type of engineering you are getting into. It is probably safe to say there are literally a 100 different engineering specialties. Often you will be using a variety of languages and in some niches Python is a big factor. Sometimes it might be commercial programming / math processing languages, like MatLab. Electrical engineers may be focused on Verilog and similar languages. Embedded engineers may be focuses on C++ and microprocessor assembly.

I think the important thing here is that until you really firm up your job future you can't say for sure what language you will be using. Your could get into a business where the engineers are deep into Fortran still. It is not a question of choosing between the two but rather being educated to the point that you can rationally start in a new job where the default language could be anything.

There is a huge difference in my mind between learning to program for ones self and learning CS so you can have a career. If you want to enter the workforce learn CS properly, if you have a personal interest you can dive into any language you like.

•

u/DriftingAndromeda 7m ago

For simple personal tools plus engineering down the line, I'd lean toward whichever one gets you building things fastest. Rust has a steeper start because the borrow checker forces you to think about ownership early, but its compiler errors are very helpful and it's hard to write memory bugs. C++ is everywhere in engineering, simulation and embedded work, so it's worth knowing if your future field uses it, though it has more footguns. Check what your engineering courses or the tools in your field actually use, since that should be the tiebreaker. If you're unsure, start with one for a month on a small tool and see which one you enjoy sticking with.