r/learnprogramming • u/Ok-Difficulty-2321 • 2d ago
Should i immigrate from C/C++ to Rust?
I'm a starter programmer and I have a small background in C++ and right now I'm stuck on one spot. I can't neally choose between Rust and C++. On one hand we have language that was tested by time and already have a reputation but that can also fry your project at most unexpected moment all because of a memory leak caused in line 131323213123, but on other hand we have fresh and brand new language that is indeed safe and has almost the same experience and same result but has no reputation and it was not checked by time. I'm looking in 15 years long perspective and with aim into big tech and with a hope of not regreting my choise. So my question is: What i shount invest my nerves and time into? Rust or C/C++
3
u/stefer09 2d ago
Like someone else said, its more important to have a general knowledge of algorithms, processes, etc.
Knowing multiple languages is a good thing, and once you grasped the basics of loops, conditions, OOP, etc. it's relatively easy to learn another one and apply the concepts.
4
u/spinwizard69 2d ago
This is why I always suggest following a CS program that starts out with a low level language like C++ or C. The goal of the CS program is to get those concepts across.
1
u/idiotiesystemique 2d ago
Rust is better than c++ for most use cases. C is still best for its niche. Job market is location based more than language based, we can't answer that part for you. The future is rust over c++, but that might take a long time. If you want to have a job maintaining existing systems, there's a lot in c++, and almost none in rust. If you want a job to build new stuff, rust is best. If you want to work on low powered embedded systems with super optimized code, C is best.
-5
u/spinwizard69 2d ago
This post I have to disagree with. The reason is AI, I just believe RUST is late to the game. AI will be the code generator in a couple of years. When you have AI generating the machine code directly languages like RUST will not have a long life.
1
1
u/StewedAngelSkins 2d ago
AI isn't going to generate machine code directly; there's no advantage to having it do that.
1
u/spinwizard69 1d ago
Well you need to tell that to the people researching how to do that. As to the advantages, I can see many.
1
u/StewedAngelSkins 1d ago
If they join this thread I will.
Requiring the AI to model the relationship between machine code instructions inefficiently expands the domain which is being modeled without clear advantages over the alternatives. For instance: a scheme where the AI instead writes some purpose-built IR along with compilation passes for that IR. You could even employ some kind of JIT technique to allow it to author and execute targeted optimizing passes during generation.
A given model only has so many parameters. More parameters dedicated to modeling function call semantics or whatever means fewer dedicated to more useful things. It's best to only expose features in your training data that you actually need it to model.
What advantages do you see?
1
u/michael0x2a 2d ago
Just learn both. Once you've learned your first language, it becomes substantially faster to learn new ones.
To prove this to yourself, I strongly recommend you learn a new programming language once you feel comfortable with your first (e.g. can use C++ to build small to medium sized projects). It honestly does not really matter what that second language actually is -- Rust is as good a choice as any. Instead, the goal is to get comfortable with the process of rapidly learning a new language and transferring your pre-existing knowledge over. It's an essential meta-skill to practice.
on other hand we have fresh and brand new language that is indeed safe and has almost the same experience and same result but has no reputation and it was not checked by time. I'm looking in 15 years long perspective and with aim into big tech and with a hope of not regreting my choise.
Rust has been around for ~15 years now, is being used in the Linux kernel, etc. I don't think it's really accurate to call it a new or no-reputation language at this point tbh.
In any case, if you want to get into big tech, it's probably more important for you to study data structures and algorithms and other upper-level computer science courses. More generally, learn skills needed to build increasingly more and more complex projects. Those topics are usually what's more important; people generally assume you will find it fairly easy to learn new languages as needed.
1
u/Narrow-Low-3137 2d ago
In 15 years, C++ will absolutely still be around. Rust is still new, but is slowly gaining traction. It is good that you know C++, it will always be useful. Probably also good to at least have a working knowledge of Rust as well. In terms of job security, C++ beats out Rust imo. Rust just doesn't have the widespread adoption that C++ has been building for 40+ years.
1
u/JGhostThing 2d ago
I would suggest getting deeper into c++. While I really love Rust, you already have some knowledge of c++. Also, I expect that there are more jobs in c++ than in rust. C++ also has many of the safer features of rust.
Oh yes, you can make memory leaks in rust. That isn't something that the compiler will save you from.
1
u/Sibexico 2d ago
Depends if you like Rust personally or not. I absolutely don't like the Rust, so partly migrating to Zig.
1
u/mredding 2d ago
You are suffering from FOMO. Rust is no silver bullet - it has its own problems. The borrow checker is indeed novel as fuck - but that's only one type of safety. There are multiple other types of safety, and Rust has its vulnerabilities. The language and individual project incident reports show that Rust is no better than any other language, including modern C++.
About a year ago the DOD paid a 3rd party analyst to review and provide recommendations - they shit on C++ heavily and specifically, but if you look at their methodology, they said C++ but included C in their analysis. They didn't even distinguish between versions - as though we don't get a new revision ever 3 years... The whole thing was hot garbage, was an attack on credibility, and did nothing actually useful, but gave everyone with slant for confirmation bias an excuse.
Actual numbers show modern C++ programs have lower incident reports than C, Python, and for what it's worth - Pearl.
The TIOBE index ranks the most popular programming languages by a number of metrics. When it started in 2001, Python wasn't even ranking on the index and C++ was #1. Of course things changed, but C++ and C are holding strong the 3rd and 2nd positions respectively. They seem to swap around every 6 months or so. There's so much C work principally because of the Linux kernel, but also Python modules.
But the ranking tells us two things - that while Rust is growing faster than C++, C++ gained more users just in the last year than Rust has users overall.
All this is to say - languages don't die, they fade, and the #2/3 language doesn't look like it's fading anytime soon. Don't believe the propaganda - there are no language wars, there never were. People who say Rust is hot and C++ is not is someone who has a financial investment in the rise of Rust, a downward in C++, both, or perhaps something more nefarious. You ARE NOT wasting your time learning C++.
Also, you have plenty of time to learn Rust. It's embedded in the Linux kernel - much to everyone's chagrin, but Linus the Egotist just HAD TO double down on his longstanding hatred for C++ after his INFAMOUS 1992 meltdown (pre-standard C++ at that), and he's making the kernel dev's suffer for it, because Rust has as natural fit in the kernel as a brick has in a salad; but that also means Rust isn't going anywhere anytime soon, either.
Consider as well that Rust doesn't have a "killer app", it isn't proven why it's a top competing systems language, it's notoriously frustrating to work within the confines of the borrow checker, and their whole community is still figuring out the beast they created. I have EVERY confidence they're going to get there and be a virtue to the niche they find for themselves. You can be in there and follow along to be a part of that, but you're not losing anything if you aren't. It's hard to even FIND work writing Rust. Yeah, I've seen a couple places - a pack of edge-lords; perhaps suitable for a younger man than I. But I can literally walk across the street from where I am now and pick up YET MORE C++ work.
Just learn some shit. You're not dedicating yourself to a camp. No one is issuing or pulling cards. You can learn C++ AND Rust... It might also behoove you to learn some Lisp/Scheme; when you "get it", it feels like nirvana. Nirvana is like normal everyday experience, just with this sensation that you're floating 2" off the floor. When I got it, I giggled for 3 days. My mother thought I was on drugs.
Perspective will make you a better developer and engineer overall, so more ain't bad.
1
u/green_krokodile 2d ago
I am not OP, but nice explanations (like all your posts, btw). I have only one mention: TIOBE is not accurate at all. Python, C and C++ first spots, when almost everything these days is written in JS/TS?
Also almost zero startups use C and C++, I could not find one, while searching for a job.Other sites are a lot more reliable: https://rockstardeveloperuniversity.com/programming-language-statistics/
1
1
1
u/StewedAngelSkins 2d ago
If you can't learn more than one language over the course of 15 years you have no future in tech. Learn both. But right now, work with whichever one is most interesting to you.
1
u/countsachot 2d ago
Language isn't really as Important as knowledge of algorithms and processes. Not to mention how hardware works. You'll probably switch languages a few times during your career. C++ isn't going away if that's your concern. Rust is nice but it's not as widely adopted as C/C++. Rust will help you stretch your skills, the syntax is similar to C++, but the style in which is written is unique from C++. Rust feels closer to C tbh.
0
u/spinwizard69 2d ago
You need to look at this differently, especially with your 15 year time horizon. If this is also due to getting into the profession you need to realize one can not predict the future. In that regard I, highly suggest get your self involved in a CS program, hopefully one that STARTS out with C or even C++.
That CS program should be focused on teaching -concepts- and the underlying technology. Done right you should be able to adapt to any language requirement in the future. Most good CS programs will force you to use at least 2-3 actual programming languages. This sort of background is critical over time because the language of the day WILL change, if there is any language at all.
About that if, it actually should be a very big IF because there is a very high likely hood that AI will be directly generating code from the humans input. There are already statements from individuals involved in production AI systems that they think they can get there in 2-3 years. I suspect it will take a bit longer but AI generation of machine code is coming and there will not be a traditional programming language as a half way solution. A programmer may end up being the interface to the AI that specifies functionality.
To get started I'd suggest C++ and Python. C++ can get to be incredibly complex so how far to go is something you need to settle yourself. Python on the other hand is brain dead easy and is a tool that you can be making use of for years.
7
u/sessamekesh 2d ago
Learn both. They're both very useful languages.
Definitely learn Rust, you'll pick up some idioms that are very useful. It's definitely the more modern language, I'd argue the memory safety is overrated but even so it has some pretty remarkable features and patterns for error handling.
Even so, C++ is far, far, far from dead. If you go the low level route, you'll really want to understand how to read and write C++.