Live data from Hacker News

A half-hour to learn Rust

fasterthanli.me

11–20 of 150 posts

Re: A half-hour to learn Rust

#11
Underscore is not exactly "throw away" but rather it is exactly "don't bind to variable". The difference becomes evident with the statement:

    let _ = x;

This is a no-op and the value remains owned by the variable x, and is not thrown away.

Re: A half-hour to learn Rust

#13
post #6
post #3

Only, it’s more one hour and a half rather than half an hour. Excellent quality stuff nonetheless

It's only an half an hour if you are familiar with these concepts (generics, traits, pattern matching, error propagation, etc...). Some concepts are exclusive to Rust (lifetimes/ownership), so I doubt you can get it in 30 minutes if you have never written code in Rust before.

I’ve seen this guy’s posts a few times lately, he needs to learn to edit things down. What he’s saying is good, but it is extremely digressive, and the digressions never seem to return to the original point. I’m not the audience for this so I don’t have that much time to spare reading it, but I can’t imagine that style working well for an introduction to a language.

Re: A half-hour to learn Rust

#14
post #12

> let x: i32 = 42; I'm sorry but this notation will always make me scream. C is so much simple: int x = 42; not "let", no colon, and no ambiguous "i32 = 42"

How about `let x = 42` and let type inference do the work? I used to do a lot of C-style variable declarations in other languages but I'm warmed up to Rust's really fast because most of the time I don't need to explicitly name the type.

Re: A half-hour to learn Rust

#15
post #12

> let x: i32 = 42; I'm sorry but this notation will always make me scream. C is so much simple: int x = 42; not "let", no colon, and no ambiguous "i32 = 42"

I found in "real" rust code I very rarely declare any types other than in function signatures and I keep functions pure, short and to the point.

It's so rare to have hardcoded values anyway.

Re: A half-hour to learn Rust

#16
post #11

Underscore is not exactly "throw away" but rather it is exactly "don't bind to variable". The difference becomes evident with the statement: let _ = x; This is a no-op and the value remains owned by the variable x, and is not thrown away.

Underscore can also be the equivalent of a wildcard in pattern matching.

Re: A half-hour to learn Rust

#17
post #5

Numbers could also be differentiated in Rust. For example, to make sure your "16" is an i32 you could write > let x: i32 = 16i32; Otherwise, it's a very comprehensive article. The only missing parts are the async/await keywords and the sync primitives (like Mutexes/RwLocks).

C# has a similar feature, but it's less verbose, e.g. "16l"/"16L" is a long (64-bit integer), "16u" is an unsigned, 32-bit integer etc.

I find the rust syntax a little difficult to read. Take "16i32" for example - it's not immediately clear which part is the actual value.

Re: A half-hour to learn Rust

#18
post #6

Earlier quoted context omitted.

It's only an half an hour if you are familiar with these concepts (generics, traits, pattern matching, error propagation, etc...). Some concepts are exclusive to Rust (lifetimes/ownership), so I doubt you can get it in 30 minutes if you have never written code in Rust before.

I’ve seen this guy’s posts a few times lately, he needs to learn to edit things down. What he’s saying is good, but it is extremely digressive, and the digressions never seem to return to the original point. I’m not the audience for this so I don’t have that much time to spare reading it, but I can’t imagine that style working well for an introduction to a language.

I respectfully disagree but - can't make everybody happy.

There's plenty of introductory articles to Rust in the style you desire :)

edit:

To expand a little bit, the digressions aren't just about me "getting distracted" while writing - they're very much on purpose. I always try and write pieces that expand in many different directions, because there's so much to discover, always.

Some folks come to an article wondering why Rust has two string types and end up spending an hour on Wikipedia reading about legacy code pages - and I think that's great.

My way of getting people interested in something is never a top-down, present-the-bare-minimum way, it's always about showing how what we're discussing is connected to a lot of other things, which are also fascinating and that you should check out if you want!

Re: A half-hour to learn Rust

#19
post #12

> let x: i32 = 42; I'm sorry but this notation will always make me scream. C is so much simple: int x = 42; not "let", no colon, and no ambiguous "i32 = 42"

I just made a similar comment before I read yours, but about C# rather than C, where just like C you can do:

`int x = 42;`

But since int (32-bit integer) is the default integer type, you can also do:

`var x = 42;`

If you want to use another type, for example, ulong (unsigned, 64-bit integer), you can do:

`ulong x = 42;`

Or:

`var x = 42ul;`

C#'s syntax is not only terser, but seems a lot easier to read to me. With rust's syntax, it's not immediately clear what the value is, and what the type is.

Post reply on HN