I’m still learning Rust myself. But in general it’s less complex compared with C++ and OOP. Though, for the record, aside C#/F#, I know way more about C than C++.
Rust is more like C, plus functional programming and polymorphism via interfaces called “traits”. When I first saw Rust I actually confused it with MS’s F#. Both are derived from ML and OCaml, etc, too. But to be clear for those who don’t know yet, rust is native code, not managed. It’s a “system language” used for anything really, game engines, embedded, and even operating systems.
All variables are immutable by default. There are no classes in Rust. You only get structs and enums. And enums can hold data. No headers.
Yes, you can define methods/member functions even with structs. Every “implementation” lets you define a bunch of methods for a struct as if it was a class. “Trait” definitions are like interfaces, and define method signatures that can be shared across structs implementations.
Yeah, it looks like the best of OOP but without the worst of OOP like inheritance. Class types may not be the worst, but they are totally useless as Rust proves it that mere structs work, too, when you “separate data from behavior”. Yes, you can do a more data oriented approach in C++, too, but Rust does that naturally.
Some say that C++ got a bad reputation not because it is so bad, but because new programmers abuse it that bad. Shows that C++ is more complex than Rust out of the box while doing the same thing. Rust wouldn’t allow you to do any other way.
And of course we use pointers as usual, but they are checked at compile time with the “borrow checker” that defines boundaries and memory owner ship that can at run time be auto freed when out of scope. It’s like a GC, but it’s at compile time GC, which makes Rust virtually as fast as C++ without the GC hiccups at run time that you can find in C#/F# yet still being at the same memory safety levels as managed code languages.
Coupled with immutable values you get thread safety, but no undefined behavior, no dangling pointers, no seg faults, no buffer overflows, no memory leaks, etc. There are no nulls in Rust. So no run time exceptions because of that either. All this is the stuff of nightmares in C/C++ no matter how hard you try or skilled you are.
But, you can still go “C” in Rust with the “unsafe” keyword code block/functions that can be inside normal Rust code anywhere. Though, it’s C when you use C APIs. Otherwise unsafe code is used to do very low, and specific hardware programming, or just some performance optimizations that allow you to use pointers in exotic ways but without the compiler throwing an error that would prevent your project form successfully building.
There are other features, too. You won’t find silly C like:
for (int i; i < 100; i++)
Instead you do this.
Rust uses also “functional programming” paradigms, but that’s not really new to C++ either. I just mention it because there is value in FP if done on a middle ground level. F# may go a bit overboard with FP. Even the signatures in F# are “->” math like single parameters that can make you wonder what the heck when you miss one parameter and the entire signatures changes as the compiler tries to infer the type. F# got the monad in its own way. And fanctors. So, F# got a bit too much of FP if you ask me. I’d rather use Rust that is more C like. But heck, F# is a very clean language. It’s just too bad that it’s also managed code like C#.
But for the record regarding managed code performance. The game Space Engineer was written fully in C#. It’s not too bad, but I’m not under the impression that Rust is much harder than C#. So, why bother with C#? I see people using C/C++ for GUI, let that sink in…
Well, ideally it should have been C/C++ that should have evolved this much, and they do evolve but so slow that it always allowed yet another language to spawn in the first place.
C++ got rid off the headers only now. And it’s still an unsafe language.
Rust got “editions”. Current is 2018, seems Rust can introduce breaking features much faster than other languages because of that. Internally it got three intermediate layers. Any binary compiled in 2015 edition can mix with 2018 and so on.
The IDE can be shallow for Rust. I use CLion with a Rust plugin, but the IDE support got better. And currently there is a lot of push for IDE support because soonish VS 2021 may be here. And the Rust language team clearly understands that it needs the support of MS because it ain’t just about the language itself. It’s also about jobs, so programmers having access to that language on a professional basis. MS got a lot of jobs internally. So, this isn’t just about VS supporting Rust either. I don’t even user VS, I use CLion.