News for hackers. Stuff that matters.
Re:Fighting Rust's Expressive Type System by ezekiel68 on Saturday October 24, 2020 @11:50PM (#24883710)
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.
Re:Fighting Rust's Expressive Type System by tijsvd on Sunday October 25, 2020 @02:44AM (#24884294)
I 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.

Re:Fighting Rust's Expressive Type System by atoav on Sunday October 25, 2020 @04:23AM (#24884700)
I'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.

Re:Fighting Rust's Expressive Type System by Boulth6 on Sunday October 25, 2020 @05:39AM (#24885023)
> This is one of the books which I will gladly buy once more when it is updated.

Agreed, Programming Rust is really nice and I read a dozen of Rust books already. I'll be buying 2nd edition as soon as it's available.

Re:Fighting Rust's Expressive Type System by some_account99 on Sunday October 25, 2020 @07:37AM (#24885494)
which 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++.

Re:Fighting Rust's Expressive Type System by tijsvd on Sunday October 25, 2020 @04:09PM (#24889477)
I 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.

Re:Fighting Rust's Expressive Type System by some_account99 on Sunday October 25, 2020 @05:33PM (#24890091)
Maybe 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?
Re:Fighting Rust's Expressive Type System by dochtman on Sunday October 25, 2020 @02:22AM (#24884213)
Can 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.
Re:Fighting Rust's Expressive Type System by capitol_ on Sunday October 25, 2020 @04:11AM (#24884649)
One 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

and

https://docs.rs/git2/0.13.12/git2/struct.Branches.html

Where Branches implements Iterator.

Re:Fighting Rust's Expressive Type System by masklinn on Sunday October 25, 2020 @05:28AM (#24884969)
That 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.
Re:Fighting Rust's Expressive Type System by ReactiveJelly on Sunday October 25, 2020 @10:56AM (#24886734)
Yeah 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.

Re:Fighting Rust's Expressive Type System by lostmsu on Monday October 26, 2020 @02:56AM (#24893456)
In 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.