Live data from Hacker News

A half-hour to learn Rust

fasterthanli.me

201–210 of 342 posts

Re: A half-hour to learn Rust

#202
Very nice. As a very experienced programmer who has now learned more languages than I can remember, I generally look for these kinds of cheatsheets whenever I'm learning a new language, followed by the official documentation. Other than that, I don't personally find tutorials very useful.

The cheatsheets give me a quick intro to syntax conventions, and then the official documentation provides all the detail on specifics. I'm looking to mentally map how different PL constructs common across different languages are expressed in the new language I'm learning.

Along the way, I end up learning one or two new PL concepts. Fewer these days than in the beginning, hence it gets easier and easier to learn new languages.

Re: A half-hour to learn Rust

#203

Earlier quoted context omitted.

Yeah, when reading this I was wondering if Rust has sealed traits like Scala, and also structural typing. The extreme degree of shared syntax and shared semantics with Scala was really surprising to me.

Rust does not have sealed traits, though you can sorta contort the privacy system to do similar things if you want. We also do not have structural typing. (Generally; tuples are structurally typed but nothing else is) A lot of Rust’s language people did a lot in Scala. The language’s are pretty different IMHO.

As was explained to me, Rust has heritage from OCaml. If one squints, they can even see it still beneath the surface. I hear the original compiler was even written in OCaml.

Re: A half-hour to learn Rust

#204
post #186

Earlier quoted context omitted.

Yes, you can clone all day long and just reuse variable names as if you were writing JavaScript, but what does that do to your memory allocation?

Most languages just clone all day long, it's not that bad, rust clones (like most languages) are just to the first reference counted pointer after all.

Well, yes and no.

Eg cloning a string leads to an extra allocation and a memcopy.

If you want to get a similar performance profile to GC languages, you have to stick your types behind a `Rc>/Arc` or `Rc> / Arc>` if you need mutability.

But modern allocators hold up pretty well to a GC, which amortizes the allocations. The extra memcopying can be less detrimental than one might think.

Re: A half-hour to learn Rust

#205
post #161

As a Python programmer with limited experience with compiled languages, Rust code was more intimidating to read or look at than C++, Java or Go. After only an hour, I am overwhelmed by the sheer beauty and mature design of this language - it almost reads like Python or as well as any compiled language can. I cannot believe that I am smitten by Rust within an hour. Its features seem, obvious. My experience with Go was…

Rust makes hard things easy and easy things hard. Also reading Python code is easier (less syntax noise) on the eyes. The article above is very beginner Rust, and I won't rely on that to look at actual Rust code in the wild. If you want to take a look at what actual Rust code in the wild, take for example, a web server Actix, and try to figure out what the documentation says.

> Rust makes hard things easy and easy things hard.

I don't agree with this, and, if anything, this reads very biased.

Insofar, Rust has made my life a lot easier, and I have not run into any major issues aside the borrow checker. And this was early on. Two years now playing with the language and I barely run into it anymore.

Re: A half-hour to learn Rust

#206

Earlier quoted context omitted.

You can write Rust code with almost no lifetine annotations. That's heavily dependent on the domain, of course. But for relatively simple function signatures they are usually inferred correctly, and you can often just clone instead of requiring references.

Pretty sure if you’re deserializing a structure with borrowed references you need lifetime annotations. Copying things around to pacify the compiler hardly seems elegant.

Sure, but that's a performance vs ease of use decision.

Often you don't need to care about the extra allocations and can just deserialize to owned types.

The code for owned deserialization certainly ends up looking more elegant.

Re: A half-hour to learn Rust

#207

Earlier quoted context omitted.

Rust does not have sealed traits, though you can sorta contort the privacy system to do similar things if you want. We also do not have structural typing. (Generally; tuples are structurally typed but nothing else is) A lot of Rust’s language people did a lot in Scala. The language’s are pretty different IMHO.

As was explained to me, Rust has heritage from OCaml. If one squints, they can even see it still beneath the surface. I hear the original compiler was even written in OCaml.

Yes, especially amongst the earliest folks, there was a lot of OCaml, and the original compiler was, yes.

Re: A half-hour to learn Rust

#208

This is precisely what I was looking for when I searched for “Rust for C++ programmers” in the past. I love the Rust book, but I’ve always thought the common focus on accessibility for newbie programmers made it feel tedious for those who are more seasoned. I’d love to see more writing like this, maybe even for other things like libraries!

If you already know C++, https://overexact.com/rust-for-professionals/ might be for you (disclaimer: I wrote this)

Re: A half-hour to learn Rust

#209
post #161

As a Python programmer with limited experience with compiled languages, Rust code was more intimidating to read or look at than C++, Java or Go. After only an hour, I am overwhelmed by the sheer beauty and mature design of this language - it almost reads like Python or as well as any compiled language can. I cannot believe that I am smitten by Rust within an hour. Its features seem, obvious. My experience with Go was…

Rust makes hard things easy and easy things hard. Also reading Python code is easier (less syntax noise) on the eyes. The article above is very beginner Rust, and I won't rely on that to look at actual Rust code in the wild. If you want to take a look at what actual Rust code in the wild, take for example, a web server Actix, and try to figure out what the documentation says.

I find that advanced Python is quite hard to read. Well, I find that advanced dynamically typed languages tend to be hard to read in general, because you can never be sure what type your inputs and outputs are and what values they can take. Usually my

At least idiomatic Python shuns wildcard imports that obfuscate where symbols are coming from (that drove me insane in Ruby).

On the other hand Rust code tends to be very strict about what your types are (even more so than a language like C++ where metaprogramming is duck-typed by default). It can lead to complicated code, but baring some weird operator overloading decision you should know exactly what calls what from whom when you look at any method or function.

Rust code can be tricky to write at times, but I generally find it a pleasure to read. Sure, ultra-complicated generic code can be overwhelming, but this complexity would be here in one form or the other regardless of the language, Rust just forces you to be explicit about it.

Re: A half-hour to learn Rust

#210
post #161

As a Python programmer with limited experience with compiled languages, Rust code was more intimidating to read or look at than C++, Java or Go. After only an hour, I am overwhelmed by the sheer beauty and mature design of this language - it almost reads like Python or as well as any compiled language can. I cannot believe that I am smitten by Rust within an hour. Its features seem, obvious. My experience with Go was…

As another Python programmer I also agree. Rust's features are very mature especially compared to an old dinosaur like C. I only wish its syntax was more like Swift's which is more pleasing to the eyes and was also made by the same guy.

Minor note,. Graydon created rust and worked on Swift. He didn't create Swift however.

That said...both languages read like close siblings to me to the point I find it annoying switching between the two because I keep trying to use each ones language semantics in the other subconsciously.

Post reply on HN