Live data from Hacker News

A half-hour to learn Rust

fasterthanli.me

21–30 of 342 posts

Re: A half-hour to learn Rust

#21

In the 9th code snippet that's not an example of variable shadowing, it's just variable reassignment. Shadowing involves variable assignments in different scopes. https://en.wikipedia.org/wiki/Variable_shadowing edit: I should've called it "variable redefinition" or something like that I guess, my mistake. Reassignment is definitely not the correct terminology for this. Still, it's not shadowing because the new bindi…

In Rust, shadowing is when you "declare a new variable with the same name as a previous variable" [1] -- even in the same scope. It seems it "fell out" of how the original compiler was implemented, and there was more support to retain it than not. See: https://internals.rust-lang.org/t/history-of-shadowing-in-ru...

[1] The "Rust book" has a good explanation of shadowing, which contains a nearly identical example. See: https://doc.rust-lang.org/book/ch03-01-variables-and-mutabil...

Re: A half-hour to learn Rust

#25

A half-hour to learn Rust Jan 27, 2020 · 51 minute read · rust maybe the site's reading time estimator is broken? sarcasm intended. But seriously, it is good to have people writing things like this.

I'm guessing the code snippets are skewing the estimate.

Re: A half-hour to learn Rust

#26
post #15

That is the best article on Rust I've ever seen. Better than the Rust book. I've been saying that Rust needed a book that wasn't written by the designers of the language, who are too close to it. Now we have one.

[deleted]

Re: A half-hour to learn Rust

#27

A half-hour to learn Rust Jan 27, 2020 · 51 minute read · rust maybe the site's reading time estimator is broken? sarcasm intended. But seriously, it is good to have people writing things like this.

> maybe the site's reading time estimator is broken?

All of them are. I first started disliking Medium for just that reason.

Re: A half-hour to learn Rust

#28

In the 9th code snippet that's not an example of variable shadowing, it's just variable reassignment. Shadowing involves variable assignments in different scopes. https://en.wikipedia.org/wiki/Variable_shadowing edit: I should've called it "variable redefinition" or something like that I guess, my mistake. Reassignment is definitely not the correct terminology for this. Still, it's not shadowing because the new bindi…

There is effectively an implicit scope created by the let binding. In rust you can't reassign a variable without it being mut. The two `x`s are separate variables named x and are not at any point mutated. Reassignment would look like this: let x = 1; x = x + 1; // This obviously matters very little for an integer, but it is relevant to more complex types. You can actually see the scopes, and the progress of variable…

Oh interesting, I see now! Thanks for clearing this up.

Re: A half-hour to learn Rust

#29

A half-hour to learn Rust Jan 27, 2020 · 51 minute read · rust maybe the site's reading time estimator is broken? sarcasm intended. But seriously, it is good to have people writing things like this.

Programmers don't read, they skim in half the time, then auto-complete in their mind with false assumptions!
Post reply on HN