5

what are your guys' opinions on rust vs c++? I personally prefer rust. the only thing that I really struggle with in rust is lifetimes. I definitely feel that rust is more modern and it's pretty similar to c++ from what I've seen

Comments
  • 10
    Lifetimes are present in pretty much every language - Rust is the only one that makes them explicit and statically checked through a pretty unique type system (usually they only live in compiler analysis passes). That's great because instead of reasoning about it implicitly like in C/C++, you reason about it explicitly. It looks messier but at least nontrivial program properties are spelled out in greater detail. Systems programming isn't a trivial task and Rust reflects that arguably better than C/C++ do. Rust will feel really nice if you come from the logic/theorem prover side of things (which imo is how programming should be taught).

    I think Rust is great, not just because of the very nice, fresh ideas in the language but also because of the toolchain. It's such a pleasure defining a project and using libraries (and cross-platform dev) compared to C/C++. Also not having to deal with decades of legacy crap really does make it feel nice and fresh.
  • 4
    Rust is love, rust is life
  • 3
    i would say rust, but i never got to the point where i understood rust.
  • 6
    Lifetimes are the most original post of Rust's type system, but also quite possibly the best. Being able to specify "I need this reference to stay alive for exactly that long" is extremely powerful, as is the fact that the compiler ensures that.

    Rust can be overly pedantic at times, but most of the time, it is right and will beat memory safety into your skull to the point that, when back to C/C++, you'll just keep specifying lifetimes and ownership in comments.

    The only thing I miss in rust compared to C++ is generic specialization, but I am hopeful that it will come to stable some wonderful day.
  • 1
    @CptFox have you seen cpp guidelines? They are pretty much solving most of the problems and can be statically checked.
  • 2
    I find that C is better than CPP in most things and I find that rust is better than both when it comes to package management (cargo).

    Rust is good because it comes with a lot of modern idioms. But, in my opinion, rust will always struggle to be adopted in the mainstream for one reason - new programmers will be turned away from the language because of its strict compilation rules.
  • 2
    @iiii About pointer lifetime and ownership? Since when? Please send a link because I am properly interested in that 'o'
  • 1
    @CptFox it started several years ago, if I remember correctly

    https://isocpp.github.io/CppCoreGui...
  • 2
    Haven't really done much Rust myself but solely it's build+ packaging system (cargo) is magnitudes better than whatever tools you may use for C++
  • 2
    @LotsOfCaffeine even Bjarne himself (the creator of cpp) thinks the same 😁 that's why modules are to come to cpp
  • 2
    @iiii the modules in Rust kinda confused me at first, I'm used to C#'s "compile everything and have namespace declarations in every file" approach

    But just having a package manager is so important
  • 2
    @iiii Thanks. It still doesn't really help with structures with borrowed fields (without shared_ptr to do it at runtime), but I'm happy to have a standard for the rest of the cases.

    Said structures with borrowed fields (such as iterators) are where lifetimes shine, and will shine even brighter when we get generic associated types and lifetimes on stable.
  • 2
    C++ is "good enough" for the odd bits of dev I do. If I coded closer to the metal often though, I'd probably make the effort to learn Rust properly.
  • 3
    I feel that C++ has effectively become two languages—C with Classes and Modern C++. I gave up on Modern C++ eventually as I thought it was just easier to go all-in on Rust.
Add Comment