Live data from Hacker News

A 30-minute Introduction to Rust

doc.rust-lang.org

61–70 of 94 posts

Re: A 30-minute Introduction to Rust

#61
post #60

As someone fairly new to systems programming, I can still see why you'd want to pick a language like Rust over C. But can someone explain to me the difference between Rust and Erlang? They are both system languages, no? Erlang is much more established. But what are the key differences? And I'd ask, "which should I learn?", but that is generally not a great question...

"Systems programming" is a broad term, so you are painting in too-broad strokes.

I'm not super familiar with Erlang, so I may get some things wrong, but heres a few differences:

Erlang prefers GC, wheras Rust tends to eschew it (it's available in a library).

Erlang is dynamically typed where rust is statically typed.

Erlang is single-assignment where rust uses a somewhat more nuanced lifetime system (though that is still changing).

Erlang prefers communication over channels, while rust has immutable types that are safe to share.

Re: A 30-minute Introduction to Rust

#62
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 :)

Writing libraries you need to think about it a lot it really informs the choices for datastructures you make.

Other than that, it's considerably easier than other non-managed languages (e.g. C, C++, Pascal)

Re: A 30-minute Introduction to Rust

#63

Earlier quoted context omitted.

> C or C++ code bases get really brittle over time as developers forget what is actually going on This is very true. And one of the culprits is a lack of modules, an shortcoming that Rust avoids. A module system for C++ is grossly overdue, and I'm not holding my breath that one will be forthcoming.

What's your definition of a "module" that is not a class, not an object file, not a .so, and not a namespace? I'm not trying to be argumentative. I've seen this "C++ doesn't have modules" claim before, and I'm trying to get my mind around it.

Right now the way you use a module in C++ is to tell the compiler to dump a subset of its source-code from that module into each file that uses it. Then you tell the linker to link in the objects from that module later.

This is a pretty ridiculous and highly inefficient way of doing things (Facebook improved compile times by crafting a server just to do the preprocessing for you).

Re: A 30-minute Introduction to Rust

#64
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…

I would looooove any insight that you have on making the docs better for people who haven't done systems programming before. If you've ever got the time to type out a few thoughts, my email is in my profile.

Assuming you wrote this, you lost me in the book analogy. Once you wrote "let's ignore programming for a moment" I thought to myself, why am I here? And why are we talking about ownership? How do I set up a tool chain and write hello world?

This doesn't strike me as a 30 minute intro to Rust. More like a quick guide to what sets Rust apart from C. Perhaps my expectations would be different with a different title ("How Rust can benefit you as a working C++ dev")

Re: A 30-minute Introduction to Rust

#65
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…

I often find that you need to read a page-long faq (which is an improvement over reading mailing list flame wars over boost vs raw stl vs library-du-jour) to figure out the "right" way to do anything in C++. Now knowing my way around it reasonably well, it's not an issue for me anymore, but not a newcomer.

It's so easy to do it the wrong way, and there's so many examples of badly written or non-idiomatic C++ code strewn all over the internet that a newbie is bound to fall into that trap. This is the same kind of problem I (used to) see with PHP, that it can be fine if you do it all the "right way" and don't do "stupid stuff" but it takes a while to learn what those are. What happens in reality is they google "how to do x", copy paste the code, and modify. Who cares if it's idiomatic or anything.

Re: A 30-minute Introduction to Rust

#66

Earlier quoted context omitted.

I would looooove any insight that you have on making the docs better for people who haven't done systems programming before. If you've ever got the time to type out a few thoughts, my email is in my profile.

Assuming you wrote this, you lost me in the book analogy. Once you wrote "let's ignore programming for a moment" I thought to myself, why am I here? And why are we talking about ownership? How do I set up a tool chain and write hello world? This doesn't strike me as a 30 minute intro to Rust. More like a quick guide to what sets Rust apart from C. Perhaps my expectations would be different with a different title ("Ho…

> Perhaps my expectations would be different with a different title

Hmm yes, I will think about it. Ownership is Rust's most important and unique concept, so an intro to ownership _is_ an intro to Rust. I will think about how to make this more clear.

Re: A 30-minute Introduction to Rust

#67
post #34

Out of curiosity I implemented the two examples in C++11. For the number add I used a unique_ptr (although returning by value would be better in every way). For the shared state I used async with a lamba that calls transform and returns the modified vector through a future. This doesn't execute in parallel for each for loop though. I think something like Arc can be coded in C++ too - template wrapper that returns a R…

> Right now the extra compile-safety of Rust is IMO not worth giving up the other benefits of C++ I can't speak to everyone's use case, but for ours memory safety is extremely important. C++ is not safe, and we still see tons of memory safety issues, many security-sensitive, in practice, despite using modern C++ for all new code. Even if safety isn't as important to you, there are other reasons you might be intereste…

What kind of issues do you see still with modern C++11 code?

Re: A 30-minute Introduction to Rust

#68
post #61
post #60

As someone fairly new to systems programming, I can still see why you'd want to pick a language like Rust over C. But can someone explain to me the difference between Rust and Erlang? They are both system languages, no? Erlang is much more established. But what are the key differences? And I'd ask, "which should I learn?", but that is generally not a great question...

"Systems programming" is a broad term, so you are painting in too-broad strokes. I'm not super familiar with Erlang, so I may get some things wrong, but heres a few differences: Erlang prefers GC, wheras Rust tends to eschew it (it's available in a library). Erlang is dynamically typed where rust is statically typed. Erlang is single-assignment where rust uses a somewhat more nuanced lifetime system (though that is s…

Are there specific implementation models or areas or systems programming that favor (or have come to use more exclusively) Rust or Erlang?

Re: A 30-minute Introduction to Rust

#69
post #34

Out of curiosity I implemented the two examples in C++11. For the number add I used a unique_ptr (although returning by value would be better in every way). For the shared state I used async with a lamba that calls transform and returns the modified vector through a future. This doesn't execute in parallel for each for loop though. I think something like Arc can be coded in C++ too - template wrapper that returns a R…

> Right now the extra compile-safety of Rust is IMO not worth giving up the other benefits of C++ I can't speak to everyone's use case, but for ours memory safety is extremely important. C++ is not safe, and we still see tons of memory safety issues, many security-sensitive, in practice, despite using modern C++ for all new code. Even if safety isn't as important to you, there are other reasons you might be intereste…

I get the feeling most of these commenters who think the words "modern C++" indicate some kind of near insulation from writing security bugs are, in fact, writing security bugs.

They probably think they aren't, but by definition, we are not smart enough to immediately understand the bugs we write. Otherwise we wouldn't write them.

But hey, it's not like a programmer who overestimates his own skills is a new thing.

Re: A 30-minute Introduction to Rust

#70

Earlier quoted context omitted.

Assuming you wrote this, you lost me in the book analogy. Once you wrote "let's ignore programming for a moment" I thought to myself, why am I here? And why are we talking about ownership? How do I set up a tool chain and write hello world? This doesn't strike me as a 30 minute intro to Rust. More like a quick guide to what sets Rust apart from C. Perhaps my expectations would be different with a different title ("Ho…

> Perhaps my expectations would be different with a different title Hmm yes, I will think about it. Ownership is Rust's most important and unique concept, so an intro to ownership _is_ an intro to Rust. I will think about how to make this more clear.

I had no problem with the book analogy. I've been hovering around the periphery of Rust for a while, waiting until I understood the ownership thing before I move into it more seriously.

Thanks for writing this! I think it was a solid step in the direction of clearly explaining ownership. I know more than I did before and I'm looking forward to reading your next piece on it.

Good work.

Post reply on HN