4 ms·
I feel this blog post will be very helpful to people getting into rust for the first time. (or the second, etc time, if it turned them off the first time) I en
by ezekiel68 6y ago
I feel this blog post will be very helpful to people getting into rust for the first time. (or the second, etc time, if it turned them off the first time) I enjoy rust and I write as many of my personal projects in it as I can.
Here's a quote that really resonated with my early experience with the language:
"However many of these [common rust patterns] are by convention, rather than by language design. Their prevalence depends in part on the authors' stylistic choice. This meant I was more reliant on examples and documentation than I am perhaps accustomed to."
I find, even today, it's impossible to check documentation or read "the book", alone, and produce idiomatic rust code. Finally one breaks down and asks on Stack Overflow or one of chat or forum outlets and receives an answer which (almost always accidentally) comes across as, "Oh, didn't you know it?? We always express those ideas in this format here [example code]". I've come to accept and appreciate this way. But it can be baffling and off-putting to newbies who wonder how they should have known.
- dochtman 6y agoCan you give an example of this? I'm very curious. As an experienced Rustacean, I kind of realize that there is a lot to idiomatic style, but at the same time I've assimilated it enough that it's often no longer obvious to me.
- capitol_ 6y agoOne thing of roughly this nature is that a lot of rust code that I have read have their own types for iterators of objects. For example, in the git2 crate there is both: https://docs.rs/git2/0.13.12/git2/struct.Branch.html https://docs.rs/git2/0.13.12/git2/struct.Branch.html and https://docs.rs/git2/0.13.12/git2/struct.Branches.html https://docs.rs/git2/0.13.12/git2/struct.Branches.html Where Branches implements Iterator.
- masklinn 6y agoThat seems pretty natural? The only reason why you don't have this in e.g. python is that iterators are often implemented as generators, so the "own type of iterator" is implicit. But I remember pretty much the same thing from my Java days, if you need to iterate you have to create an iterator type. It's a bit less visible due to type erasure but it's there nonetheless.
- ReactiveJelly 6y agoYeah it's not intuitive, but there isn't really another way to do it, right? Every concrete iterator is specific to what it returns and what it iterates over. I think it's documented under something like "How to implement Iterator" but if that's not where people will go looking when they need it, then it should be somewhere else.
- lostmsu 6y agoIn C# and Python you can write an iterator using `yield` keyword. E.g. for(i in array) yield i The language then transforms this into an implementation of the base iterator interface under the hood.
- tijsvd 6y agoI think that says something about the book. I initially read the book online as well, and was put off when actually trying to get something done and not succeeding. Later, I bought "Programming Rust" by Jim Blandy, and it changed everything.
- some_account99 6y agowhich edition, because honestly i found Blandy book very little value in providing any explanation about rust beyond demonstrating page over page rust's equivalences in c++. it's just really a translation of c++ patterns into rust equivalences. no explanation, history, context about language design or idiomatic patterns from the host language. I don't know the history of The Book's date of publish/development vs blandy's book enough make this any more than a conjecture: it seems like blandy's book is a re-take on the book. also, i am not saying The book is any good beyond a tour of the language. come to think of it, it's actually less like TC++PL or D&EC++, and more like the tour of c++.
- tijsvd 6y agoI bought mine March 2020. > it's just really a translation of c++ patterns into rust equivalences. no explanation, history Perhaps. I came from a strong C++ background, maybe that's crucial when reading it. It all just made perfect sense to me.
- some_account99 6y agoMaybe the 2020 edition is better than the one i got from 2017 but if things aren't entirely different, basically rust to you is just a reapplication of C++ idiom for a language that targets a compiler which was historically developed to emit machine code based on c++ on the demands of cpp semantics?
- atoav 6y agoI'd second this book recommendation. It is not only the best Rust book out there, it is also one of the best books on any programming language I have read so far. This is one of the books which I will gladly buy once more when it is updated.