Hacker News new | ask | show | jobs
by sidlls 3534 days ago
I suppose if I identified with any language, C++ would be it. I have the most knowledge and experience writing code in that language. I've been learning Rust lately and have written a few toys with it. I'll share my thoughts.

1. The main benefit of Rust is its nearly cost-free safety guarantees. It's much harder to write code that is prone to UB with Rust than with C++. The comparison is almost silly, in fact, from that perspective. It comes with a runtime cost (e.g. drop flag checks, bounds/other memory access checks) in some cases, but for all cases other than those requiring even that last bit of performance this cost is tiny in comparison with the work the rest of the program is doing and well worth it in my opinion.

2. The primary reason for choosing it over any other language is context dependent. This leads me to my last point.

3. It would be fine to use for anything, really, but I think in the sense of "most appropriate" that you mean, it's "most appropriate" for systems programming that needs to be as fast as C++, but not necessarily melt-the-metal fast. Primarily this is because: a) it's as fast as C++ in almost all cases (and probably faster than equivalently-safe C++ in at least some cases) and b) it's much less likely I'll write code that smashes stacks, has data races, blows up memory or does a bunch of other crap that's trivial in C++ (or other languages). Even in cases where melt-the-metal fast is necessary it seems possible to do in Rust, but it just takes a lot of effort. That's deliberate on the part of the Rust developers, and it's difficult to argue against the reasoning behind it.

Where Rust might really shine is helping a new generation of programmers write performant code that is safe without having to learn by trial-by-fire.