4 ms·
A big problem with Rust right now is that the documentation is awful. This has two implications. The less important one is that the language is harder to lear
by Animats 12y ago
A big problem with Rust right now is that the documentation is awful. This has two implications. The less important one is that the language is harder to learn. The more important one is that there's no architectural document that prevents Rust from becoming a collection of features in search of an architecture. If you have to clearly explain in writing how something works, and the explanation is overly complex, that's an indication that simplifying the design may be necessary.
The basic concept of ownership in Rust is simple. Everything has either a single owner, or a reference counted cell as owner. Things which cross thread boundaries have a locked reference counted cell as owner. Temporary references to single-owner objects are allowed, but must have a shorter lifetime than the primary ownership, and this must be demonstrated by simple static analysis. That's straightforward.
Making those restrictions usable seems to require many features and much churn within the language. It's too soon to tell how this will come out. As I'm mentioned before, I'm bothered by the need for "unsafe" code in pure Rust that's not calling hardware or C code.
- ossreality 12y ago>A big problem with Rust right now is that the documentation is awful. Wha? Steve has been putting a ton of effort into it and it shows... When is the last time you looked? If you're one of these people that wants to announce your opinion in every thread and remind us that you've said them before, it would be worthwhile to keep up with the evolving language. How you can understand Rust's lifetime tracking requirements and not understand why "unsafe" is needed... Just grep through std lib for usages of "unsafe" and see why it's needed.
- MichaelGG 12y agoWhat Rust code needs to be unsafe, other than the sharing primitives? Rust has really come together well over the past year, and no doubt with 1.0 providing a serious release, a lot of gaps will get filled in. That said, I've found it pretty easy to get running with Rust, and the IRC channel is one of the best I've been in.
- kzrdude 12y agoThis code from BinaryHeap doesn't need unsafe, but it gladly uses it for performance. The comment in the code explains it. http://doc.rust-lang.org/src/collections/binary_heap.rs.html#501-544 http://doc.rust-lang.org/src/collections/binary_heap.rs.html...
- steveklabnik 12y ago"Gladly" isn't quite accurate: https://github.com/rust-lang/rust/pull/4146#issuecomment-11408758 https://github.com/rust-lang/rust/pull/4146#issuecomment-114... This is exactly how I'd expect to see `unsafe` used: as an additional optimization in situations where you can't get better in any other way, and with a big-'ol comment explaining exactly why. Well, one of the ways, at least.
- Animats 12y agoThat's exactly how unsafe ought NOT to be used. All they saved here were about two machine instructions per operation. On some superscalar CPUs, those might be overlapped anyway. "Swap" is a safe operation in a single-ownership world, and Rust used to have a swap operator. That was taken out, because it could be done with a template. The penalty is that the compiler doesn't know you're doing a swap. Swap has some potential optimizations. I am very suspicious of unsafe code for claimed "performance" reasons. That leads to exploits and backdoors.
- steveklabnik 12y agoI agree that 'unsafe for performance' should be something of a last resort, but do not have the knowledge to comment on this specific situation.
- dbaupp 12y agoWhere did you get the two machine instructions number? A swap could easily be a exchange of e.g. 16 (the size of a slices &[T]/&str on a 64-bit computer) or 24 bytes (Vec<...>/String) (or larger), and there's no way to use single SIMD instructions for these in general. Also, "per operation" is vague, since the swaps would have to happen repeatedly in a loop, so a single .insert call is likely to result in multiple swaps.
- stewbrew 12y agoI agree with respect to the quality of the documentation. I hope they put some effort in rewriting the docs before the 1.0 release. The problem is exacerbated by a load of out-of-date tutorials you come across when searching the internet for hints. IMHO they should let cool things down a bit before pushing out 1.0. (And no, having to hang around in IRC channels in search for an answer isn't really an option.)
- steveklabnik 12y agoWould you mind also answering https://news.ycombinator.com/item?id=8783393 https://news.ycombinator.com/item?id=8783393 , then? Thanks.
- ethbro 12y ago> I'm bothered by the need for "unsafe" code in pure Rust that's not calling hardware or C code. Why is this bothersome? I'm curious, as to me the advantage is not in full-program safety, but in having a distinction between portions of a program that are guaranteed safe and portions that aren't. Or, to turn it another way, Rust isn't giving you guarantees about 100% of the code you're looking at: it's vouching for the >0% (hopefully!) but <100% that's marked safe. It seems an elegant, realistic engineering solution to a hard trade-off between performance and safety.
- Argorak 12y agoThe great part is that Rust has a bot that will ask for thorough code review if something inside an unsafe { } -block has changed. Static analysis for pragmatic reasons is really common in Rust even now. (BTW, unsafe {} is still a whole lot safer than standard C)
- steveklabnik 12y ago> A big problem with Rust right now is that the documentation is awful. Could you get more specific for me, please? There's certainly much room for improvement, but I can't fix what I don't know about! > If you have to clearly explain in writing how something works, Are you aware of our RFC process? Changes _do_ have to have extensive, written explanations.
- mnemonik 12y agoFWIW, I've found the Guide incredibly helpful, and in general found the docs very satisfying. (Although I do wish the pointers guide was more complete :) ) The API docs + search in the docs are incredible IMO. I'm in absolute love with rustdoc. Having links to the source right there is the most valuable thing ever, both when trying to understand how to use a given API, and when trying to write similar things its really useful to be able to look at how others have done things.
- steveklabnik 12y agoAwesome. I'll consider bumping up the Pointer Guide in my priorities.
- ldng 12y agoI think people expect _more_ documentation. The guide can only get you so far IMHO. That said, if I may say so, string handling should be more throughly detailed. It's one of the first thing new comers will stumble upon. Especially for those who come from a dynamic language. Heck, I think it might even been the perfect occasion to exemplify the borrowing system. Edit: Just some further thoughts on the spot (feel fre to ignore if you strongly disagree). It feels at the beginning that the guide is kind of building things up. In that spirit I would put an expended String chapter just after "7 Comments" since simple example programs can already be made without what's following (well except maybe loops). Maybe something in the spirit of "14 Guessing game" but smaller. That is, with less, more recently read, concepts to refer to.
- steveklabnik 12y ago