Andy_Pagin World Chat Champion
Joined: 08 Nov 2010 Karma :
|
|
Rogerborg nimbA
Joined: 26 Oct 2010 Karma :
|
Posted: 16:22 - 08 Feb 2018 Post subject: |
|
|
Better for what purposes? ____________________ Biking is 1/20th as dangerous as horse riding.
GONE: HN125-8, LF-250B, GPz 305, GPZ 500S, Burgman 400 // RIDING: F650GS (800 twin), Royal Enfield Bullet Electra 500 AVL, Ninja 250R because racebike |
|
barrkel World Chat Champion
Joined: 30 Jul 2012 Karma :
|
Posted: 20:52 - 08 Feb 2018 Post subject: |
|
|
Idiomatic Rust code is usually about as fast as idiomatic C or C++. So performance loss isn't normally something you need to suffer to choose Rust instead. (In some of my test programs, Rust was actually faster than C.)
It's memory safe. That's a major win; stay away from unsafe code, and you'll never get an access violation again; it's also substantially harder to create an unrooted memory leak (but nothing will stop you e.g. adding infinitely many items to a list, and you can create reference counted cycles).
The type system is much better. It's not as flexible, but it's better rooted in theory. C++ has a hacker's type system, with a variety of after the fact patches and fixes to try and fill in the holes, particularly around exception safety. Rust's type system is roughly based on ML, but adapted for execution on metal without GC.
Modelling data structures is much more tricky because of the constraints the type system, and in particular the borrowing system enforces. If you have cycles in your data structures, you're in for a somewhat painful time.
The borrow checker also makes writing concurrent code much easier. Again, it limits some idioms, but it's harder to get into trouble.
To write solid C++, you need to select a bunch of features that work well together, and then stay on the happy path. Wander off the path, and trouble will find you before long. There's an amazing amount of complexity in C++ - people have written books about how to e.g. write exception safe library code - and the language is full of traps for the unwary, like object slicing if you forget to hide your assignment operator, single-arg constructors acting like implicit conversions if you forget explicit, through to the awesomely complicated interaction between templates and overload resolution. Like I said, if you use your delimited subset of C++ and strictly follow a set of patterns, you can be productive. But if you're aware of the bubbling sea of shit underlying it all, you'll want something with more solid foundations.
Rust is something with more solid foundations. Not only do I think it's worth learning; I think people should stop coding in C and C++, and code in Rust instead. The world will have fewer bugs and security problems.
You do need to internalize how the borrow checker works though, and that takes time. ____________________ Bikes: S1000R, SH350; Exes: Vity 125, PS125, YBR125, ER6f, VFR800, Brutale 920, CB600F, SH300x4
Best road ever ridden: www.youtube.com/watch?v=s2MhNxUEYtQ |
|