On Fri, Oct 18, 2013 at 4:47 PM, Huon Wilson <[email protected]> wrote:
> On 19/10/13 10:37, Jerry Morrison wrote:
>
>
>
> - Use postfix syntax for pointer dereference, like in Pascal:
> (~rect).area() becomes rect~.area() . That reads left-to-right with
> nary a precedence mistake.
>
> While Rust’s auto-dereference feature and type checker will sometimes
> catch that mistake, it's better to just fix the failure mode. All security
> holes in the field got past the type checker and unit tests.
>
>
> Do you realise that `~rect` means "create an owned box [a pointer] that
> contains `rect`" and isn't not a dereference in Rust? (That is performed by
> `*rect`.)
>
Ah! Thanks. I had the mistaken impression that one had to use the same
dereference operator for each kind of pointer.
>
>
> - Don’t let ; default its second operand. Require an explicit value,
> even if (). That fixes an opportunity to goof that might be frequent
> among programmers used to ending every statement with a ;.
>
>
> `;` isn't a binary operator, and anyway `a; b` doesn't affect the
> behaviour of `b` at all. Could you describe what you mean a little more?
>
> (Also the type system means that writing `fn foo() -> int { 1; }` (with
> the extra & incorrect semicolon) is caught immediately.)
>
Yes, I'm thinking of, say, { 1; } as a function body or a match clause.
If the type checker always catches a stray (;) when it matters [no problem
with { (); } ], then great. No bugs there.
I found it difficult to explain Rust's (;) to a programmer used to
statement syntax. He said he couldn't look at a line and say "it's wrong"
if it either has a (;) (like Ruby, Python, Go) or if it doesn't have one
(C, C++). My solution was to explain it like C's (,) sequence operator but
it can be infix or postfix [meaning { 1; () } ].
>
> - AIUI, let mut x, y defines 2 mutable variables but |mut x, y| defines
> mutable
> x and immutable y. This is harder to learn and easier to goof.
>
>
> `let mut x, y` doesn't exist at the moment precisely because of the
> confusion; one has to write `let mut x; let mut y;`. (Relatedly There is a
> proposal to make `mut <ident>` a valid pattern, so that `let (mut x, y)` is
> valid: https://github.com/mozilla/rust/issues/9792 )
>
>
> Thanks for listening!
>
> --
> Jerry
>
>
> _______________________________________________
> Rust-dev mailing
> [email protected]https://mail.mozilla.org/listinfo/rust-dev
>
>
>
> _______________________________________________
> Rust-dev mailing list
> [email protected]
> https://mail.mozilla.org/listinfo/rust-dev
>
>
--
Jerry
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev