Live data from Hacker News

A 30-minute Introduction to Rust

doc.rust-lang.org

11–20 of 94 posts

Re: A 30-minute Introduction to Rust

#11
post #10
post #8

Earlier quoted context omitted.

Just to temper your enthusiasm, the compiler errors can sometimes be irritating, especially when you want to do something the you are pretty sure will be safe. But on the whole if you work with it the pay-off is well worth the minor annoyances. Having the compiler always check your code for memory safety is a huge win for refactoring - C or C++ code bases get really brittle over time as developers forget what is actu…

> especially when you want to do something the you are pretty sure will be safe (It's worth noting that often the compiler is complaining because it actually isn't safe.)

Indeed, I’ve been certain that something that it’s not letting me do is safe, only to realise a bit later that actually it was right in a subtle way.

There are certainly some valid things that the compiler will forbid which you then need to work around instead, but by and large I trust the compiler to be right more than I trust myself.

(Bear in mind, still, that these sorts of arguments of Rust’s superiority in such things are frequently only applicable for comparisons with languages like C++; often they are the sorts of things that a managed language would not have a problem with, though also not infrequently it would lead to things like data race.)

Re: A 30-minute Introduction to Rust

#12
post #10
post #8

Earlier quoted context omitted.

Just to temper your enthusiasm, the compiler errors can sometimes be irritating, especially when you want to do something the you are pretty sure will be safe. But on the whole if you work with it the pay-off is well worth the minor annoyances. Having the compiler always check your code for memory safety is a huge win for refactoring - C or C++ code bases get really brittle over time as developers forget what is actu…

> especially when you want to do something the you are pretty sure will be safe (It's worth noting that often the compiler is complaining because it actually isn't safe.)

Yes! It is often showing a flaw in your mental model, which can be painful at first, but once solved it will ultimately result in more reliable code.

Re: A 30-minute Introduction to Rust

#13

Is the language stable enough to learn yet (given that I won't be really using it immediately)? I've been putting off looking at it because it seemed very much in flux.

There is a very special fun in learning Rust. It isn't stable in the sense that your code from last week will compile this week. On the other hand, it is currently stable enough that all the major concepts are there and most changes are either syntax or API. So reading up on the changes of last week and some search and replace cover most things. Also, most API changes now are introduced through deprecations. All breaking language changes have an RFC process.

The great thing is to see a language while it is still being shaped. Have something you don't like or something that is incredibly clunky? Get involved! The barrier will never be lower. Backwards compatibility is not a thing yet! If the change makes sense and you can muster the resources for it, there is no one holding you back. Code review for pull requests is also awesome, all of my pull requests were accepted on the second or the third try - but for the better!

On top of that, it is a really interesting language on it's own right with interesting concepts worth learning.

Re: A 30-minute Introduction to Rust

#14
I've only ever used GCed (and largely dynamic) languages up until now (Python, JS and Clojure primarily); C is alien and C++ is frankly terrifying. With all that, I've been having a ball using Rust to solve Project Euler problems, with astonishing speed compared to what I'm used to.

It doesn't quite have all the libs you might want for general development yet, but for the things it's currently equipped for it's a lot of fun, and surprisingly easy. (Up until I find myself in a quagmire of lifetime problems of my own making. Looking forward to the coming lifetimes inference enhancement.) It's a surprisingly reasonable functional programming environment too.

Re: A 30-minute Introduction to Rust

#16
How much cognitive overhead is it to think about ownership all the time once you get used to it ? Coming from a GC-languages background I had a hard time thinking in those terms last time I played with it. I ended up having .clone() littered all over the place :)

Re: A 30-minute Introduction to Rust

#17
post #14

I've only ever used GCed (and largely dynamic) languages up until now (Python, JS and Clojure primarily); C is alien and C++ is frankly terrifying. With all that, I've been having a ball using Rust to solve Project Euler problems, with astonishing speed compared to what I'm used to. It doesn't quite have all the libs you might want for general development yet, but for the things it's currently equipped for it's a lot…

Why do you see C++ as "terrifying"?

Yes, it is a very powerful language and there can be a lot to it, but it shouldn't "terrify" you.

These days, it's generally quite easy to avoid much of its C heritage (including potential security pitfalls) if using the so-called "modern C++" techniques, but the extra power and flexibility is still there if you do ever need it. There are numerous ways of easily avoiding manual memory (or other resource) management, too. The STL and Boost, among numerous other libraries that are out there, offer lots of convenient, high level functionality. The portability of C++ code is often quite excellent, the language and its standard libraries are quite stable, and there are multiple commercial-grade implementations from numerous vendors/projects. You probably won't find anything else that gives you a high degree of performance along with high level abstractions, while also giving you the peace of mind that your code will still compile just fine years or even decades from now.

While it's certainly possible to to overboard and misuse C++ to a point where it causes serious problems, one of the best things about C++ is that it doesn't force you to do that. You generally don't pay for what you don't use, and it's certainly possible to use a very effective subset of the language much as one might use Java or C#, or even Python and JavaScript.

I'd say that C++ is even easier to use than JavaScript is. C++ is much more sensible in so many ways, and nowhere near as quirky or just outright broken in fundamental ways like JavaScript, while also providing at least some type safety and other compile-time checks.

If you want a stable, portable, safe, well-supported language that offers high level functionality without the performance tradeoffs of other languages, then I think that a modern subset of C++ could very well be exactly what you're looking for.

Re: A 30-minute Introduction to Rust

#18
post #17
post #14

I've only ever used GCed (and largely dynamic) languages up until now (Python, JS and Clojure primarily); C is alien and C++ is frankly terrifying. With all that, I've been having a ball using Rust to solve Project Euler problems, with astonishing speed compared to what I'm used to. It doesn't quite have all the libs you might want for general development yet, but for the things it's currently equipped for it's a lot…

Why do you see C++ as "terrifying"? Yes, it is a very powerful language and there can be a lot to it, but it shouldn't "terrify" you. These days, it's generally quite easy to avoid much of its C heritage (including potential security pitfalls) if using the so-called "modern C++" techniques, but the extra power and flexibility is still there if you do ever need it. There are numerous ways of easily avoiding manual mem…

C++ is not safe in the same sense that Rust is. Without the use of "unsafe", Rust is designed to never segfault or have undefined behavior, ever. Even a modern subset of C++ cannot make the same guarantees (consider iterator invalidation, etc.)

Re: A 30-minute Introduction to Rust

#19
post #16

How much cognitive overhead is it to think about ownership all the time once you get used to it ? Coming from a GC-languages background I had a hard time thinking in those terms last time I played with it. I ended up having .clone() littered all over the place :)

I find that it's no more mental overhead than it is in C. The nice thing is that the development cycle ends up being faster than C for me because I don't have to spend as much time in front of the debugger.

Re: A 30-minute Introduction to Rust

#20
post #17

Earlier quoted context omitted.

Why do you see C++ as "terrifying"? Yes, it is a very powerful language and there can be a lot to it, but it shouldn't "terrify" you. These days, it's generally quite easy to avoid much of its C heritage (including potential security pitfalls) if using the so-called "modern C++" techniques, but the extra power and flexibility is still there if you do ever need it. There are numerous ways of easily avoiding manual mem…

C++ is not safe in the same sense that Rust is. Without the use of "unsafe", Rust is designed to never segfault or have undefined behavior, ever. Even a modern subset of C++ cannot make the same guarantees (consider iterator invalidation, etc.)

I'll gladly use modern C++ techniques and a bit of care, even if that means only getting say 90% or 95% of the safety that Rust potentially offers offers, if it also means that I can get my code written today, and I can trust that it'll still compile unchanged tomorrow, next week, and probably a decade from now.

I think it's great what Rust could potentially offer software developers. But it's still pretty theoretical at this point. The language and standard libraries aren't sufficiently stable enough for serious, long-term use, currently. I hear we may start to see the beginning of such stability at the end of the year, but until it actually happens, Rust isn't very useful, while C++ is.

Post reply on HN