I'm a rust fan, even more so of cargo (wish C/C++ had a cargo). But at the end of the day it almost always boils down to transition costs vs. benefits, and the benefits currently don't outweigh the transition costs IMHO.
I often wonder - how big does a code base have to be before an advocate of these ideas (ie: "rewrite it in X cause X is abstractly better") might be inclined to backpedal and reconsider their advocacy?
One example from the VBS2/Armed Assault 1/2 they replaced the way arrays references are handled. Previously array's assignment was a copy. They changed it so array's assignments would mirror java's references and only the pointer to the buffer would be copied eg.. copy on write. They had so many idiotic edge case conditions that they reverted back to the old method.
So when I say they just need some major backers it would be for new system and applications that would take advantage of the new language. Re-writing most game engines today doesn't have a strong business case. Writing new games/software and shipping faster is more important.
Maybe it is like politics, rather than attacking your opponents you should offer something that they do not. Then you will build your own constituency and gain influence. It will take a long time, but if you keep on providing benefits to users, then attrition might take you to the top. When someone attacks your camp, ignore them. You do not need a better way to attack them, you just need to stick to the knitting and make your offer provide benefits to users. External forces will likely decide whether or not you overwhelm your opponents.
The about only languages that could compete right now are extended Ada for high assurance environments and Fortran variants for HPC. They are old but not dead and quite usable if you have the dollars to buy proprietary or invest time.
Microcontrollers and constrained environments are another critical niche for C and C++, especially given proprietary compilers.
Rust does not go far enough in safety to displace Ada (or Spark variant) while not offering improved performance and comparable portability with all the pains of a new language. It also does not do build once deploy everywhere stuff Java and JS attempt. Rust is neither here nor there. A good effort but not a solution.
If you offer something groundbreaking, you don't need to match portability. Many people will be willing to make the tradeoff.
> Microcontrollers and constrained environments are another critical niche for C and C++
Why do you assume Rust can't be used for these niches? I understand the potential issues with old environments, but what about modern/future ones?
> It also does not do build once deploy everywhere stuff Java and JS attempt.
Rust compiles to JS today. It will eventually compile to WebAssembly.
If not, then again, Rust has no clear selling point. It really has to be better at something. Matching is not good enough.
It definitely is not easier to use nor embed. (To compete with the likes of Python, Ruby or Clojure.)
Similarly for an embedded scripting language or rapid prototyping.
Or how about the original purpose of Rust, to rewrite a rendering engine? That's an incredibly widely used platform.
There's an OS being written in Rust that a lot of people are really excited about. There are very few languages other than C/C++ that are actually viable for rewriting an OS and would, in and of themselves, prevent entire classes of bugs.
This thread is about WebAssembly. For that, those are your only options currently.
"Easy" has no objective definition. Does it mean "getting code to run"? Or does it mean "writing bug-free code"?
For me, easy means the latter. It means that human error is harder to introduce into the code. A great language should not rely on the shaky pillars of discipline or expertise, because neither of those are easy to find or enforce, nor are they consistent. A disciplined expert might be too sleepy to write safe code, for example.
Rust is much easier to use than C and C++ because the compiler helps you so much and replaces discipline/expertise. That's the whole point. Rust prevents you from doing something you don't intend to do (or at least it does it better than most languages).
Python, Ruby, and Clojure don't have the same guarantees, and none of them can be used without garbage collection, making them unsuitable for a variety of cases where Rust can be used.
In fact error messages rust produces rival the terrible nature of ones in older C++ compilers thus far.
The compiler only prevents you from making mistakes. Intentions do not even enter into it. See, some of the performance critical code in our apps has to work around even the lax C++11 rules. It is completely impossible in rust without using unsafe stuff liberally - specifically gets about 1000x slower and this matters a lot. Compilers know nothing about intentions, nor can a borrow checker enforce intentions unlike a type system.
This seems like a gratuitous misrepresentation. A compiler does not need a proof suggestion system to help you.
> In fact error messages rust produces rival the terrible nature of ones in older C++ compilers thus far.
No, it doesn't. The error messages are wonderful and constantly improving.
> It is completely impossible in rust without using unsafe stuff liberally - specifically gets about 1000x slower and this matters a lot.
Can you give specific concrete examples?
Software is slow, your OS and browser have taken 20+ years of C/C++ development with top professional development teams to become the nearly tolerable products they are.
That's... actually one of the best descriptions I've ever heard about these tradeoffs. :)
For C it was Unix.
For JavaScript it was the web.
My guess for when something like that will happen with Rust? Never.
Unfortunately, verbose, anal-retentive languages like Rust are simply poorly-suited for writing new, mind-blowing, must-have thingies. On the scale of languages that support exploratory programming, I'd put Lisp at the top, JavaScript fairly near the top, C somewhere above the middle (though it was quite close to the top when it was new), and Rust somewhere down in the FORTRAN and COBOL region of the spectrum.
Note that this is completely orthogonal to type-safety, running speed, or any other traditional measure of programming language merit. The shoals of the language ocean are littered with the wreckage of "better" languages (the various Wirth languages, e.g.). What really matters is whether a programmer can sit down and casually explore a cool idea in a few minutes of spare time, and you can't do that in a language that requires half a page of code to concatenate two strings.
Swift has managed to roll type safety (more or less) into a language that's actually fun to use, or at least not actively painful. Rust hasn't.
A Swift or Go inspired simple syntax could revive Rust.
I've been doing this for years with Rust. I'm doing it right now, in fact! The most popular piece of software I've ever written started off as a fun experiment in Rust on an airplane ride.
> and you can't do that in a language that requires half a page of code to concatenate two strings.
Great news then! Rust doesn't require half a page of code to concatenate two strings.[1]
[1] - https://play.rust-lang.org/?gist=ed677c7e279f406d0be1c7f70b5...
I would be very careful about JIT performance being even close. See, the language does not even expose SIMD well. Doing anything hard realtime (heck, even more complex UI) with a JVM in the way is a big pain.
(No, reducing amount of bugs does not do anything when pitted against well tested mature software that already exists.)
There are lots of good answers in the comments here. I think Rust has a good story for why you might choose it over C/C++ for some uses today, but it's still early days. If Rust is going to take share from C/C++, it will do so over the period of decades, not years.
So that's what's preventing ME from using rust instead of C++
Were you using zinc or some other project as the base? I figure it is an arm cortex * in your case.
EDIT: Zinc seems to not have been updated in awhile I'm not sure what the current status is of other mcu efforts. I bet some of the other rust folks can elaborate.
See your post sounds like a say so story without data behind it.
That alone makes me want to crack open some STL code just to spite them, and I hate C++!
I did a lot of ada programming (radar) and we had a fairly large library of wrappers to the C network/ ipc / process control that the operating system provided. It was a royal pain. So much so that at least a couple subsystems moved to C (mainly to use the math libraries......)
Perhaps a transpiler would be better.
Or, if you're more of the skeptical sort, Rust doesn't seem to be enough better. You could argue that C++ developers don't think they write code that creates memory issues very often. So they underestimate the benefits. (And the borrow checker is a different concept, so they may also overestimate the costs of switching.)
The net result, though, is that they perceive the benefits to not be worth the costs.
Plus the argument was mostly pertaining to new code.
That's why most projects, companies, and even governments tend to strip down the rules that govern them to what is necessary for them to function (e.g. separation of religion from state for governments).
The common reason given by the rust community to justify their behavior is that technology does not exist in a vacuum, and that technology can not be separated from politics. I completely agree. However, politics should be tackled on a layer incompletely independent from technology. Mixing the two only causes instability and uncertainty for rust. Here are two risks that arise from this mixing. I'm sure there are many, far more serious, risks besides these two:
- What happens when (not if) a significant shift in values occurs in the community? Will it collapse?
- What about technical or legal changes to the project that were driven by community values rather than technical or legal merits? This is not far fetched when technology and politics are made inseparable in the way it was done in Rust.
I use rust in a professional context, and I appreciate what it brings in terms of technical benefits. but I would be lying if a said this aspect of it didn't worry me. I can not recommend its adoption to colleagues from other companies if asked for this very reason (I was asked once so far).
Community instability or the mere perception of such is a big barrier to adoption, at least for companies.
As a C++ developer, I think Rust's main selling point (memory safety) isn't as big of a problem as it's made out to be. For every unsafe memory access that results in a crash or exploit, there are millions and millions of memory accesses that work just fine and never cause a problem. Tools like Coverity and Valgrind can catch a ton of errors, and its not clear Rust offers any significant advantages over C++ with Coverity.
Parallelism is nice, too, but C++ already has a ton of options there: OpenMP, MPI, TBB, OpenCL, standard library threads, boost/standard library async tools, etc.
On the other hand, as an end user, "written in Rust" or "written in <any language>" isn't something I care about. I don't even remember the last time I had a piece of software crash due to a seg fault, so a vague promise of being "safer" isn't good enough to accept an otherwise inferior product.
I guess to summarize, C and C++ developers are going to keep writing C and C++ and if Rust is going to take over the world, the people advocating for it will have to write better software in it and beat out software written in the other languages.
As an end user running a server, i very much care about whether my web server has vulnerabilities. And the promise about safety is not vague, it has clearly defined semantics.
To comment on your last point, it's seeing some light already, ripgrep is already beating grep in performance and is purely written in rust. And i agree that this is how rust will beat C++(if ever), by writing "better" tools than those already exist.
See, people don't care about safety, they tend to want the language to get out of the way. C++ does that because it does not get in the way of a C standard library. Or other system specific stuff.
Rust gets in the way enough that the benefit seems not worth it, and it brings few benefit in the server space over, say, Java if performance is not the paramount concern.
It's definitely an area where the closed source tools are ahead of the OSS alternatives, but there are open source (and free closed source) alternatives to Coverity. PVS Studio, for example, has a free download: https://www.viva64.com/en/pvs-studio/
> As an end user running a server, i very much care about whether my web server has vulnerabilities. And the promise about safety is not vague, it has clearly defined semantics.
You say that, yet you're still running a ton of software written in C and C++.
Nice assumption. Much of the software I use is actually implemented in Rust. And soon, I'll be using an operating system that's 100% written in Rust, with a 100% Rust Servo-powered web browser. It's only a matter of time.
In addition, I've also implemented my servers (web server included) in Rust, and they have zero dependencies upon C/C++ software, so your entire point is rendered invalid.
How does Rust compare against C++ with Coverity? Because that's the real baseline Rust should compare to.
Basically the net effects are a mix of: 1. Push more computation to compile time rather than runtime 2. Verify a lot more state at compile time, preventing dangerous or nonsensical state from occurring altogether 3. Because of 2,you get hard guarantees about the runtime state e.g there is no chance of encountering undefined behavior in safe Rust 4. Building, testing, and deploying are all quite straightforward in almost every Rust project. If you can get away with simple statistics, benchmarking is very simple too. The ones that don't typically have native non-Rust dependencies
For many, Cargo is the main selling point of Rust. Then there's the ADTs, move semantics and move-semantic-powered features(borrow checker & compile-time-checked state machines), compile-time static code analysis, FP capabilities, traits and trait-based generics, pattern matching, and the miscellaneous tools and communities surrounding Cargo / Rust. None of which you can obtain with C++. Not to mention how much better the syntax of Rust is compared to C++ -- being able to succinctly express complex patterns in simple, human-readable terms with no room for context-based ambiguity.
Of course your C++ code will probably not be as safe as your Rust code, but many people don't care about that.
At least until multiple threads or processes happen or you have hard realtime requirements.
So my question is: when can I use Rust on the Cortex M0 (or on a 32 bits RISC-V), with an interactive debugger, preferentially from a simple IDE?
If you have megabytes of flash to spare, it could probably be fine...
Most of Rust's "safeties" are only compile-time, and so have no effect on binary size.
The technically best format doesn't always win. Just look at Betamax vs VHS.
So Scala or Kotlin replacing Java, or F# replacing C# may be a better analogy. What happens there, is that Java and C# are improving just enough that many people are simply not considering the change... And C++ are trying really hard nowadays too - new version with interesting features every few years etc...
(By the way - I'm a Rust fan, and also a functional programming fan, so I would be happy if C++, C#, Java would slow down a little to let the alternatives really catch up popularity;)
1. Write an app in rust.
2. Use a rust library in that app, via the native rust interface (using c interfaces negates a lot of the pros of rust).
3. Dynamically link that app to the distro repository version.
4. Have the distro apply security updates to that library without recompiling my app.
5. Ignore cargo completely.
As a user I want to:
1. Not download and install multiple copies of common rust libraries (as is the cargo norm).
2. Not be in doubt whether a particular application is using the latest patched libraries.
It seems that rust community has learned from the mistakes of c, c++, and java. But they failed to learn the successes as well.
As for the multiple copies issue with Cargo: I generally agree with you that this definitely feels like 1 source of major blow up in project compile times, and it would be nice and useful if that were reduced as much as possible. But there is a reason that this system is in place: each crate defines how it compiles and consumes its dependency crates, so if crates A and B both depend on crate C, then A might compile and consume C differently than B does. This results in effectively different libraries once compiled, and ATM there is no way to predict in advance what the effect of any given compile flag will be since any flag can switch on/off arbitrary code. Hence Cargo keeps A's C dependency separate from B's.
Then there's the not doubting whether an application uses the latest patches. Up to a point, this can be automated through exploitation of SemVer: if Cargo could figure out that a new library version is API and ABI compatible with the previous version then I'd argue that Cargo should perhaps just auto-update it. A bigger issue is what happens when a new major version of the library is released, as those tend to break APIs in order to perform maintenance. That is something that as of yet has not been automated.
It's a rust issue because it's up to the rust compiler to generate ABI compatible binaries, at the moment there is no ABI so there isn't much distros can do. It seems they have no intention of adding one any time soon: https://github.com/rust-lang/rfcs/issues/600
This is why system libraries are nearly always in c and not c++. The ones that aren't (Qt) have a long history of broken language bindings.