5 ms·
I said this in a previous comment on a different story, so I'm going to copy-paste the content of that comment with some minor edits: The bfnightly tutorial is
by andolanra 7y ago
I said this in a previous comment on a different story, so I'm going to copy-paste the content of that comment with some minor edits:
The bfnightly tutorial is a very good tutorial, but I do want to warn that it's not always terribly idiomatic Rust: Herbert was using the writing of the tutorial as a way of practicing Rust, so there are places where the explanations aren't quite correct and other places where the code isn't what an experienced Rust programmer would write. An example that jumped out at me (this from Chapter 1.7) was the use of
&s.to_string()
which is an expression that could be shortened to just s. (Specifically, s has type &str, calling to_string() on it converts it to a String, and borrowing it allows it to be coerced back to a &str but now with unnecessary copying.) Elsewhere (this from Chapter 1.2) it has explanations like
> Copy and Clone allow this [type] to be used as a "value" type (that is, it just passes around the value instead of pointers)
which is also not a correct explanation, or at least is a misleading one: things can still be passed by value even without Copy and Clone and without any pointers at all. (Arguably, he meant, "You can share the value without using borrows," but that's not what the explanation said.)
That said, all this is nitpicky (and I suspect that Herbert would be receptive to feedback along these lines—I just haven't had a chance yet to provide it!) because the tutorial's explanation of roguelike-writing is still very good, and in fact I've been following it as a rough guide for writing a tutorial on top of a different Rust library myself! But I do want to warn about using it as a model for learning Rust specifically.
- a1369209993 7y ago> > "value" type They mean a nonlinear (or nonaffine) type, as opposed to a affine type - that can only be passed by reference if you don't want to get rid of it yet - which they would presumably call a "reference" (or "by-reference") type. It's a correct explanation, but ambiguous (not misleading, but perhaps confusing) terminology.
- leshow 7y agoClone doesn't have anything to do with that though. Copy types are passed 'by value' without a move (so are not affine). But a Clone type doesn't change anything except to add the clone() method.
- thebracket 7y agoThanks for the explanation. I'll get that clarified/cleaned up in the tutorial soon. Tracking it on the associated Github as issue #73, so I don't forget.
- thebracket 7y agoThanks for that! (I'm Herbert, made the tutorial; took a weekend away from the computer and it hit HN - nice surprise!). I definitely need to go back and fix a lot of my early Rust (it gets better) and some explanations like that. I welcome bug reports and PRs on the GitHub ( https://github.com/thebracket/rustrogueliketutorial https://github.com/thebracket/rustrogueliketutorial ) if you find more.