3 ms·
I mainly program in C and C++, but have recently started a side project in Rust. So these are thoughts from a Rust newbie (which I still think can be valuable):
by cornstalks 11y ago
I mainly program in C and C++, but have recently started a side project in Rust. So these are thoughts from a Rust newbie (which I still think can be valuable):
Pros:
- Pattern matching is beautiful, and is one of the things I miss most when not working in Racket.
- I love their static typing. I think they hit a sweet spot with type inference inside of functions but required types to be specified as parameters (too much inference can make it hard to know exactly what type something is, too little inference means I spend all my time writing type signatures).
- Borrowing and lifetimes are neat and have helped me avoid some lifetime-related bugs.
- Being able to call Rust code from C is a huge win, and I think this world needs more "systems-level" languages than C and C++.
Cons:
- Borrowing and lifetimes. This is actually is a huge pro, but sometimes the compiler can spot a lifetime issue that I don't understand (which makes fixing it hard). I'll get better with this with time, but associating lifetimes with object types is a bit confusing and hard to do if you want to do anything nontrivial. Again, I'm sure this is mostly because I'm a newbie, but it's also reality.
- Verbosity. Rust is actually concise for the most part, but if you want to pass a &str to a function, but have a String, (which, FYI, is fairly common in my experience, as most string-related functions take a &str), you've got to either call as_str() (which is unstable) or dereference-reference (i.e. &*) the String. There are a few simple things that require you to be more verbose than some other languages do.
Overall I like Rust. I think it's worth experimenting with, but I wouldn't start a really serious project with it right now (because it's so young and volatile). If someone wants to use it for a really serious project, I'd suggest checking out Rust in another year or two when it's a little more mature.
- steveklabnik 11y agoGlad you're having a good time with Rust. :) One small note: > if you want to pass a &str to a function, but have a String You can just add a & to your String. &String coerces to &str. Deref coercions are one of the few places where Rust does an implicit coercion: http://doc.rust-lang.org/nightly/book/deref-coercions.html http://doc.rust-lang.org/nightly/book/deref-coercions.html
- cornstalks 11y agoAh, cool, that's much better! Is that relatively new? I swear you had to do &* if you had a String and & if you had a &String. Edit: Ah, here: https://github.com/rust-lang/rfcs/blob/master/text/0241-deref-conversions.md#benefits-of-the-design https://github.com/rust-lang/rfcs/blob/master/text/0241-dere...
- steveklabnik 11y agoIt's not only new, but there wasn't any user-facing documentation until a few weeks ago. I'd been waiting to make changes to the book until after beta, and the re-organization of the TOC I did made me realize that I was missing a few things, this and UFCS being the primary two.