Hacker News new | ask | show | jobs
by wcrichton 3534 days ago
Rust is a replacement for C++. It is meant to be a modern, general-purpose systems language, where "systems" generally means anywhere you need to be close to the metal. This includes areas like embedded systems and high performance computing. Modern means it has features and tooling you expect from languages in 2016. For example, on a language level, Rust has type inference, sum types, pattern matching, proper generics, and a decent macro system. A modern language should also be memory safe, and Rust opts to ensure memory safety at compile time with the borrow checker (as opposed to runtime with a garbage collector like in most languages). As for tooling, it also has a proper package manager, which believe me, is incredible compared to handling dependencies in C++.

So why would you choose Rust? If you need to use C++, because you need performance, or low-level access to memory, or any other reason, then you should choose Rust instead, because it's better for all the reasons listed above. The biggest strike against Rust compared to C++ is library support--people have been writing C++ and C libraries for decades, and Rust is a new language, so it won't have the same level of support.

3 comments

While Rust is positioned firmly as an option in the same situations where C or C++ would be chosen, I'm personally of the opinion that it has a great potential of capturing use cases of higher-level languages as well, with the advent and work of Rust running on WebAssembly, it will become one of the first serious web client language alternatives to Javascript.

It's partly because of the memory safety features. There have been quite a few people I've noticed coming from languages like Ruby and Javascript and being successful. Whereas I think C and/or C++ might have been more challenging, again b/c of memory safety (GC's are a lovely thing to rely on, until they get in your way). The compiler offers a huge advantage here, because while it is true that it is much more restrictive than other languages, it also almost guarantees that your code is correct.

As an old C hack, with bad memories of C++, and a hater of the memory footprint of Java and the horribleness of the great GC pause; Rust has been a joy to learn and use. It's like bowling with the bumper rails up as an adult, and no one laughs at you (well, maybe they do, but you never throw a gutter ball!)

Yes, what wcrichton said. Additionally, I have a suggestion. One of the deciding factors for me to fall in love with Rust was my habitual use of metaphor to distance my personal feelings from the issue at hand to reach an impartial decision. In this case, I suggest you replace "libraries" which may hold emotional significance for you with another concept of similar enough nature. Bias may also come from misperceptions, such as some inexperienced web devs feeling compelled to use jQuery to make everything, or naïve hobbyists thinking Arduino boards are the hammer for all nails.

For the sake of hypothetical example, presume I have had a long history of involvement in some C++ libs which I associate with good times, hilarious IRC sessions, friends, and pouring love into the labor of creating them during 0300 caffeine overdoses. How could I possibly evaluate leaving this behind without such bias?

Many choices are vulnerable to silly human biases which are hard to detect. Debating C++ versus Rust seems to be tough for some, and technical arguments have a propensity for becoming circular, so here's an analogy instead.

- Imagine, (if you have no extreme attachments to the web) that we have created a new web with new protocols, software, hardware, solved most crypto issues, authentication is reliable, we created the safe and anonymous place of everyone's (some ppls) dreams. Most of the advances are wonderful and (mostly) fueled by the latest research and smart minds, but there are a few bugs. Overall, an improvement and well adopted but still needing polish. The problem? All the old content isn't there. Some amazing new experiences await, but reddit and youpn are not unless you pull up an old web browser. If you were tasked with creating new content, which web would you choose and why?

I propose devs consider following either this, or some other method to evaluate C++ vs. Rust more objectively and try to set attachments aside. If, rather than thinking "but I won't have libX", you ask "how can I implement this functionality better today", you may decide that casting off old clutter is liberating and insightful.

I hope this helps some of you.

If you think Rust is ready for high performance computing, I suspect you don't do HPC for a living and you haven't tried to do it with Rust. It's not just missing the needed libraries.
Can you expand on that?
What else is missing?
I think it works as a C replacement in HPC. Maybe not a C++ replacement (mostly because of missing integer generics).