News for hackers. Stuff that matters.
Re:Death to C by marvel_boy on Saturday May 02, 2015 @09:56AM (#9477043)
Newbie here. Can anyone share their experiences with Rust?
Re:Death to C by cornstalks on Saturday May 02, 2015 @10:12AM (#9477105)
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.

Re:Death to C by steveklabnik on Saturday May 02, 2015 @10:16AM (#9477123)
Glad 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

Re:Death to C by cornstalks on Saturday May 02, 2015 @10:43AM (#9477235)
Ah, 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-dere...

Re:Death to C by steveklabnik on Saturday May 02, 2015 @10:57AM (#9477288)
It'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.
Re:Death to C by Eerie on Saturday May 02, 2015 @10:11AM (#9477097)
Newbie here. My first language was Python, then I wanted to learn a so-called low-level language, but not C or C++, as I felt I don't have THAT much free time to waste.

This left me only Rust, and it is a pleasure to learn. The compiler errors are very helpful, and so is the community. You can take your time and gradually discover new stuff, like the difference between heap and stack, static/dynamic dispatch, Move vs. Copy semantics, usefulness of tagged unions in combination with pattern matching and so on...

Re:Death to C by mdup on Saturday May 02, 2015 @10:26AM (#9477172)
And if you ever want to learn C++ later (C++11 specifically), you'll have a big chunk of the work already done. Rust's move semantics are very helpful to understand C++ smart pointers, for example. Also, lambdas/closures. You'll also miss how you were babysitted (in a good sense!) by the Rust compiler, whereas C++ does not care if you mess up with dangling references!
Re:Death to C by steveklabnik on Saturday May 02, 2015 @10:03AM (#9477061)
I just posted this paper[1] to HN. It's an bachelor thesis comparing Rust, Go, and C for high performance computing.

The author claims to have 'moderate' experience with Rust and C, at least.

It includes a story about how the Rust version actually caught an error in the C and Go implementation.

1: http://octarineparrot.com/assets/mrfloya-thesis-ba.pdf

Re:Death to C by vbezhenar on Saturday May 02, 2015 @11:17AM (#9477359)
I generally work with high level languages (Java, JavaScript, Scala) but I always loved C (and in some ways C++) because it's so close to metal.

I fell in love with Rust. Usually I (internally) complain about a lot of things in languages. There are many drawbacks and bad design decisions. It might be hard to express but there's sense of engineering beaty. And I like Rust almost in every way.

So far I wrote a bunch of little programs and some simple parser (bitmessage protocol). I didn't have any real problems. Macroses looked a bit clumsy, I hope they'll see some overhaul, but they did their work. Much better than cpp anyway.

And I can say that it's just so easy to write code when you're 100% sure there are no problems with memory management. There are billion of other little things making life easier, but painless memory management is the big one.

Re:Death to C by st3fan on Saturday May 02, 2015 @10:03AM (#9477064)
I'm interested in those stories too. Also do a search for Rust in the story subject here on HN. There are many many 'one week with rust' and 'moving to rust' articles posted. Many are interesting reads.