Live data from Hacker News

A half-hour to learn Rust

fasterthanli.me

41–50 of 342 posts

Re: A half-hour to learn Rust

#41

> There is a special lifetime, named 'static, which is valid for the entire program's lifetime. I've heard this many times before, but as the guide[1] says: "You might encounter it in two situations... Both are related but subtly different and this is a common source for confusion when learning Rust." 'static means different things for references and trait objects. ie. 'a: 'static --> reference with lifetime 'a lives…

The wording that "'static means different things" is a bit misleading. It means the same thing, but the meaning different because of the context: Lifetime: lifetime means that the first lifetime outlives (is as long or longer) the second Type: lifetime means that the type is constrained by the lifetime. Because 'static means "the lifetime of the whole process". That means that the type is not constrained.

I find it very confusing.

T: ‘a is T outlives ‘a; but types are not generated at runtime.

All types are static; which is to say they are created at compile time and exist for the lifetime of the program.

Or does rust generate type variants on the fly at runtime?

I didn’t think it did...

It is a constraint applied to arguments at compile time... but r, that’s what I thought anyway.

Re: A half-hour to learn Rust

#42

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.

Firefox' reader mode estimates it at 35-45, if that helps :-)

Re: A half-hour to learn Rust

#44

Earlier quoted context omitted.

The wording that "'static means different things" is a bit misleading. It means the same thing, but the meaning different because of the context: Lifetime: lifetime means that the first lifetime outlives (is as long or longer) the second Type: lifetime means that the type is constrained by the lifetime. Because 'static means "the lifetime of the whole process". That means that the type is not constrained.

I find it very confusing. T: ‘a is T outlives ‘a; but types are not generated at runtime. All types are static; which is to say they are created at compile time and exist for the lifetime of the program. Or does rust generate type variants on the fly at runtime? I didn’t think it did... It is a constraint applied to arguments at compile time ... but r, that’s what I thought anyway.

A type constraint like T: ‘a or T: Trait is constraining values of type T, not the type T itself. That is T: ‘a is saying “all references in values of type T live at least as long as ‘a”. This includes ‘a = ‘static and the vacuous case of T containing no references.

Re: A half-hour to learn Rust

#45
post #17

> And here's a toilet closure: |_| () > Called thusly because |_| () looks like a toilet. Pure poetry! Real talk though, this is a great introduction.

I've been staring at this for a minute, but please help me seeing a toilet in this? Is it a top down view perhaps?

Re: A half-hour to learn Rust

#46

It only took me a couple of hours to port one of my old C programs, an utility to produce a hexadecimal and ASCII dump to Rust. The Borrow checker didn't even faze me. All I needed was plenty of Google-fu and my coding skills. JetBrains CLion and git are also very useful tools.

> It only took me a couple of hours to port one of my old C programs, an utility to produce a hexadecimal and ASCII dump to Rust.

Writing C code with Rust is a very different experience than converting C code to idiomatic Rust. There is more to porting than doing 1:1 conversions between keywords.

And by your description your utility basically reads words and prints their value. That doesn't really venture too much beyond the hello world territory.

Re: A half-hour to learn Rust

#47
post #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!

Is there a name for this behavior? Sounds like something that is categorized as a cognitive bias?

I'm confident that this does not only apply to programmers :)

Re: A half-hour to learn Rust

#48
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.

You may be also interested in the many existing teaching resources published by non-language-designers (whatever that means for a community-driven project like Rust), such as Rustlings and Rust by Example at https://www.rust-lang.org/learn if the book doesn’t satisfy whatever criterion you think disqualify it. Some of it is published via the rust-lang.org website, but it was/is maintained by different people who work on the language, compiler, std lib (etc). The project has a large number of people across many teams: https://www.rust-lang.org/governance

Re: A half-hour to learn Rust

#49
>In this article, instead of focusing on one or two concepts, I'll try to go through as many Rust snippets as I can

I really like this. One of the things I like to do when learning a new language is to go to http://www.rosettacode.org/wiki/Rosetta_Code and just go through snippet examples for certain common tasks.

Just quickly going through examples to me feels much easier than trying to learn from principles.

Re: A half-hour to learn Rust

#50
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.

There are a few other well regarded resources. Programming Rust from Blandy, Orendorff, and Tindall/O'Reilly is great if you have lots of knowledge in C/C++. Rust in Action from McNamara/Manning is great if you prefer to learn by building projects.

Disclaimer: am the author of Rust in Action

Post reply on HN