by ilovecaching · 4y ago · 0 comments
Rust is perhaps the language that people SHOULD be using, but likely won't. Until someone can offer something as simple and easy to learn as C and also can automatically do the things Rust provides without asking the programmer to give double in mental effort, I don't think we will replace C in a major way.
Edit: Ok maybe a bit dramatic, but I really hoped we would get working modules with c++17 and here we are still years away...
Granted the only way to fully enjoy them is being on Microsoft ecosystem, but hey plenty of us are.
It is not about how easy is it to write rust. It is about how, as a C programmer you are going to explain that your code is safe.
I know that as a long time C programmer, I still make occasional mistakes that lead to memory corruption.
In production code, there are still way to many pointer bugs. Use after free, etc. That needs to end.
Newsflash, it's not a language's job to make software safe. It's job is to make programmer's job as simple as possible: ie. writing new software. If your language fails to do that, people will not use it, plain and simple.
How else could you explain the popularity of languages such as Python and Go?
I didn't really understand Rust, until I saw a Cppcon talk about how to use STD.unique_ptr correctly, and I realized that the rust borrow checker is just that talk implemented in a compiler.
However, if the project needs a low-level language. Then skip C and C++ and use Rust.
Almost from the start, high level languages have been about safety. In assembly, memory is untyped. That leads to way too many bugs. So languages evolved to get more eleborate type systems. Compare for example K&R C with lacked function prototypes with current C that does have them. That saved huge numbers of bugs.
Traditionally, garbage collectors had to be used to maintain memory safety. However, that conflicts with many of the uses of C. So Rust had to come up with something that is both safe and compatible with C.
What kind of logic is that? "Because Google sells your data, I don't have to worry about memory safety bugs in my code." Come on.
Maybe your criteria isn't universal?
There are easy languages like Python or Go. But they are not suitable for many low-level, high performance tasks.
Rust is competing in the domain of easy to use languages. It is about low-level system code.
Edit: Rust in not competing in the domain of easy to use language
In a sense Rust very much is competing in this space. Consider the extensions to JS (wasm), Ruby, Python, and others that make it easy to call out to Rust. This is being used for performance critical sections of code (or access to high quality stable network and security focused libraries). This competes directly with that native language but offers a path that is easier than C or other options.
Rust appears to be finding a lot of success in that space.
Probably, yeah. At least in a world where openssl is actually so hard that doing stuff yourself seems like a reasonable idea, because theoretically secure doesn't do anything for you if the thing is too hard to actually use - there's a reason PHP utterly dominated webdev even when it sucked for security.
> Rust is competing in the domain of easy to use languages.
Then it loses. If you meant to write that Rust is not competing for easy to use, then it loses separately, because technically superior but too high of a barrier to entry still loses (there is a reason we aren't all exclusively running software written in Ada on OpenBSD).
And I hope that people stop preaching and would live and let live.
Rust is much much more gentle to learn than C: when you don't understand what a pointer is and how it works, you get an explicit error message given by the borrow checker and you can just ask on the official discord channel for beginners and you've solved your problem.
If only we had discord 12 years ago... The reason you struggled with C is simple: lack of theoretical knowledge. Your teacher should have started with core workings of a CPU before he showed you C.
Maybe he did, but you simply didn't bother to learn?
> Being in the position of "I need to learn a first systems language, should I pick C++ or Rust" is not very common, IMO.
What makes you think that. Everyone who learns systems programming is in this position at some point. Perhaps not if they learn at university and the language is chosen for them, but that just pushes the choice onto the university itself. And universities are increasingly offering Rust courses.
Of course, plenty of programmers aren't systems programmers and never will be. But that doesn't negate the need for systems programming languages, as demonstrated by the continued use of C and C++. If you do need a systems languages then Rust can make a good case for being the simplest. And could well become the de facto standard over the next few years.
Rust to me is starting to feel like how Haskell was a decade ago, where it seemed like everybody was talking about it but serious adoption was always just on the horizon.
But maybe my expectations are just too high. It seemed quite exciting at first to see everything being rewritten in Rust but I guess that’s not how the software world really works. Old projects are entrenched because they take many years of dev time to mature
C++ uses far exceed systems programming.
1) is as safe and as fast as Rust, or at most 1.5x slower
2) offers "fearless concurrency" and easy, safe, and efficient parallelism
3) has sum types and a good static type system
4) has great tooling and package management (see cargo)
5) has a vibrant and growing ecosystem
So far, that language doesn't seem to exist. Most fail at points 1+2.
That's some very thoughtful and noble goal. Maybe people who use C++ (and bunch of other languages) are not the ones whining.
Rust is first a system programming language with zero-cost abstractions with the least possible pain, then it is a safe language, way safer than C++.
In any case I am following the community and I have a hard time finding people saying C++ is nice for them. There are few people who have been coding C++ for 20+ years and "love" it but they are far and between. Almost nobody tried both Rust and C++ and continued using C++ for new projects.
So I predict Rust won't replace C, they have different use cases, but it will make a dent in C++.
Why won't it? I haven't really used rust or LLVM before, so I am genuinely curious.
I recommend the 2nd edition Oreilly book + writing lots of code for about a month or possibly two. After that, I think many will agree it isn't nearly as hard to write as they initially thought it would be.
The biggest bonus: Writing Rust is very fun. I can't pinpoint why this is, but I totally understand why it keeps getting voted favorite language. A total joy to write.
It was the phenomenal Rustlings course that got me over the learning hump.
Of course most of the work gets done by the compiler safe guarding and guiding during development. People make noise about lifetimes etc but once you are ready to pay the penalty of Arc (and in most cases if you are using lifetimes you are already on the verge of using Arc). Same with using cloning as needed. End of the day, these incur a predictable and acceptable performance penalty than many other languages do while providing good safety.
C is neither simple nor easy to learn. Incorrect and buggy C is simple and easy to learn.
If you think C is "simple" and "easy to learn", your C code is almost certainly full of undefined behavior bugs and security holes.
By the way, it is sooo easy to test for them,
https://googleprojectzero.blogspot.com/2021/12/this-shouldnt...
Writing C with a "how hard can it be?" attitude is a great way to get a CVE named after you.
Rust won't make systems programming any easier, it will still require the usage of unsafe part of the language. Only, you will also have to deal with a much more complex langage than C. That is why Rust has failed to replace C and C++.
1. https://insights.stackoverflow.com/survey/2019#technology-_-...
2. https://insights.stackoverflow.com/survey/2020#technology-pr...
3. https://insights.stackoverflow.com/survey/2021#technology-mo...
So, I agree with you, it will probably not become a replacement, but it succeeded in providing a credible alternative that has been used by many already.