7 ms·
The Advanced Rust Programming Language Book Draft
- Gankro 11y agoAuthor here. Didn't really want to post this to the wider programming community yet, but oh well. This is basically the first draft. Lots of errors and TODOs. Source is here if you want to file issues or patches: https://github.com/rust-lang/rust/tree/master/src/doc/tarpl https://github.com/rust-lang/rust/tree/master/src/doc/tarpl
- Analemma_ 11y agoNo problem! Is there someplace we can go to be alerted when it is ready?
- Gankro 11y agoSo it's in nightly today, so barring a tragedy it will land in stable in ~8 weeks I think. I'll probably repost it everywhere when that happens. This and The Book are living documents anyway -- they'll never be done. This just literally landed last night, though.
- adamnemecek 11y agoChanged the title to "The Advanced Rust Programming Language Book Draft". Better :-)?
- Gankro 11y agoThanks!
- evmar 11y agoIn a book that opens with "Unlike The Rust Programming Language we will be assuming considerable prior knowledge", you don't need the simple ownership example.
- Gankro 11y agoEven if assuming considerable knowledge, it's nice to be able to refresh the reader on basics here and there. That text is largely just reserving the right to not explain everything (also I'm moving away from it in general). Also: what example? There's like a hundred examples. Edit: If you mean the examples here: https://doc.rust-lang.org/nightly/adv-book/ownership.html https://doc.rust-lang.org/nightly/adv-book/ownership.html They're a recurring example that we deconstruct in later sections. There's no need to make them needlessly complicated.
- themartorana 11y agoAgreed. I work in Go, JS, Python, bash, Lua, Objective-C, Java, and C# (among others) every week. Sometimes I need a quick refresher on the topic at hand. (How many times I've put a colon at the end of a Lua function line...)
- dang 11y agoIf you'd prefer that we demote the post until the material is more ready, I think it's reasonable to offer an author that prerogative.
- Gankro 11y agoEh, I'm already at the top of HN. :P More eyes to find errors before it makes into the beta channel, hopefully!
- axaxs 11y agoI apologize to ask this, but what is Rust's end game or claim to fame? It seems to a beginners eyes as if it is a new, far more complex c++.
- chadzawistowski 11y agoIn a word - "ownership". It's what makes sure you always close your files, free your memory, and avoid data races.
- MichaelGG 11y agoRust doesn't enforce that. Recently it was shown that Rust can leak memory. Memory safety is the real thing it guarantees, without the cost of a GC. "Easy, safe, zero overhead memory management" might be a one line pitch.
- Gankro 11y agoI 100% agree that Rust doesn't guarantee an absence of leaks in any formal way. I dedicated a section to this fact: https://doc.rust-lang.org/nightly/adv-book/leaking.html https://doc.rust-lang.org/nightly/adv-book/leaking.html However I will say that Rust makes it a lot harder to accidentally leak resources (it's trivial adversarially -- but I don't consider that an interesting programming environment YMMV). In e.g. Java you need to remember to `close` a File -- in Rust it will close itself as soon as you stop using it unless you do some wild things. We can't formally guarantee anything better than the Java scenario; it's equivalent to whoever you pass a file to having to call `close` on it. However the defaults are reversed: In Java you don't close a File by default, and have to explicitly do something to close it. In Rust you close a File by default, and have to explicitly do something to not close it (mem::forget or Rc cycle). This is a pretty general theme for the wins Rust provides: it picks the best default so simple things are simple, but gives you all the tools to bypass that default. By default you want to close files. By default you want to free memory. However you can leak these resources when it makes sense. The most interesting case for me is our HashMap: we default to SipHash seeded with some OS entropy to prevent algorithmic complexity attacks. This is an explicit choice to protect our users against a relatively obscure problem. Honestly, it's probably not what most users of HashMap need. Determinism and speed is probably nicer. And yet the cost of not having that safety guard when you need it is pretty extreme. However if you know what you're doing you can just grab a community crate with a different hasher and plug it into our HashMap. Easy as a single type annotation: https://github.com/shepmaster/twox-hash/blob/master/README.md https://github.com/shepmaster/twox-hash/blob/master/README.m...
- taliesinb 11y agoTo anyone else who spots the switched around 'b' and 'c' on the repr(rust) page: don't bother, I've already created a PR.
- jimmoores 11y agoGreat to have a resource like this. By way of providing some hopefully constructive feedback, the language seems a bit excessively informal: "Safe Rust is For Reals Totally Safe. Unsafe Rust, unsurprisingly, is not For Reals Totally Safe. In fact, Unsafe Rust lets you do some really crazy unsafe things". I get the idea that's it's trying to be friendly and street, but it's a bit out of place in a document like this (I was just waiting for 'shizzle' to pop up). There also looks to be an excessive use of emphasis (italics).
- Gankro 11y agoHaha, yeah I like to be a bit silly here or there. I might tone it down, but on the other hand I find it makes the text a bit less dry to not take yourself too seriously. :) re italics: https://github.com/rust-lang/rust/pull/27414 https://github.com/rust-lang/rust/pull/27414
- Gankro 11y agoAlso RIP this intro: https://github.com/Gankro/rust/commit/a42a41520584e28a8fb5e4f0b8b2e89900377011 https://github.com/Gankro/rust/commit/a42a41520584e28a8fb5e4... (one of the many reasons I refused to squash this glorious history)
- unfamiliar 11y agoI see what you are aiming at, but honestly this informal style is hugely irritating to read for me, and is probably the main reason I haven't delved further into rust - I just can't spend more than 5 minutes reading the guide. It seems like it takes twice as long to get the information across because there are constant "quirky" remarks, weird and anthropomorphisations of computers or code, or "humorous" observations about coders. I agree the italics are annoying; there really isn't any need to stress particular words, people can read and if you write well it will be pretty obvious which words are supposed to be emphasised ("really" really doesn't). In general the tone comes across as a mix between cocky and patronising ("this book contains invaluable information" - how modest). For example, the two opening paragraphs basically told me nothing that the title didn't. And then we have things like this: >With that said, Rust is totally a safe programming language. What the hell kind of a statement is this to put in an advanced programming book? It adds nothing, sounds childish. Just let the content speak for itself, stop trying to be relatable or funny. Sorry if I'm coming across as bitter and whiny, but I am disappointed that this is suffering from the same problem as the guide for me. I honestly think it would be good for the project to have someone else to be writing these guides. EDIT: > Safe Rust is For Reals Totally Safe. > That's totally awesome. > Low-level programming cares a lot about data layout. It's a big deal. > TODO: ALL OF THIS OMG cringe... For some constructive criticism, I think Julia's docs really hit the right mark. Here is their introduction: http://julia.readthedocs.org/en/release-0.3/manual/introduction/ http://julia.readthedocs.org/en/release-0.3/manual/introduct... There is a lot of information on that page, a clear mission statement, not too dry but still manages to speak to you like an adult.
- shmerl 11y agoThis is great, I'll get to it when it will be in a solid state. I'm also waiting for some good high level chapters on Rust's approach to OOP and so on.
- felixangell 11y agoPretty good read, even if it's a draft. Only thing that bugs me a little is the informalities, and reading "That's it." after something was explained.
- hacker_9 11y agoAuthor no doubt understands programming, and the ins and outs of Rust, but has a harder time conveying his ideas in written English. For one italics are used so much to the point of being annoying after the first 3(!) paragraphs. When something is written in italics, the reader puts more emphasis on the pronunciation of the word, lengthening the amount of time they read it for. Do this enough times and the writer starts coming across as sarcastic, and even seems to be mocking the very language constructs he is writing an advanced tutorial about! No doubt this was not intended, and I would urge the author to take a few days off before coming back and re-reading their work, so they can try and see it from the perspective of an outsider.
- AlisdairO 11y agoI actually really enjoy the informal language, but I appreciate it's not universally loved. Wonderful content, regardless.
- baseballmerpeak 11y agoExactly
- Manishearth 11y ago> No doubt this was not intended, I'm pretty sure the informal tone was very much intended. There's not much sarcasm there though.
- hacker_9 11y agoYes it is informal, but the overuse of italics makes it come across as mocking, which is what I was referring to.
- krallja 11y agoSeeing this book is what finally got me to go through The Rust Programming Language.