Re:Facebook puts bounties on bugs in the D programming langu...
by jnbiche on Friday November 15, 2013 @08:17PM
(#6743149)
I'm not the downvoter (in fact, I upvoted you since you provided a non-emotional, useful, rational comment), but I disagree that those rules are pretty simple. They may be useful to know, but even the heuristic you provide above is fairly complicated for a beginner. But it's nice to know there are parallels in C.
Re:Facebook puts bounties on bugs in the D programming langu...
by jacques_chester on Saturday November 16, 2013 @02:07AM
(#6744019)
Without knowing Rust, I think it would nice if the sigils were replaced with keywords.
Eg.
x: owned mut Type
x: mut Type
x: Type
Reasoning: My memory is not what it used to be. I hate having to constantly look stuff up to remind myself what what this or that sigil means in this or that language.
- I need ownership (e.g. because I want to push the value onto a vector): take either directly by value (i.e. `x: Type`), or (very rarely) via an ~ (i.e. x: ~Type).
- I don't need ownership, but wish to mutate, `x: &mut Type`
- I don't need ownership and don't need to mutate: `x: &Type` (the most common case)
That is, once you've understood which values need to be owned by what, it all just falls out from there. (Note that this "ownership" concept happens in other languages (e.g. which function should free this pointer in C, which function should close this file handle in any language), it's just not explicit; Rust is just forcing the programmer into making the relationships explicit, which reduces mistakes.)
In general the most common pointer is &, then &mut, and then, if you're writing a data-structure, ~, but otherwise ~ is very rare. (Dynamically sized vectors and strings are written as ~[T] and ~str respectively, and aren't included when I say "~ is very rare" since there's no way to put them on the stack.) I've ignored @, because it's (1) rare in idiomatic code, and (2) isn't implemented fully (it's currently behind a flag, to make it clear that it's not ready for prime-time). The "Boxes" and "Move semantics" parts[1] of the main tutorial are more modern, and may help.
TL;DR; the borrowed pointer tutorial overcomplicates things.
[1]: http://static.rust-lang.org/doc/master/tutorial.html#boxes