On 08/15/2012 09:10 AM, Gareth Smith wrote:
Hi,
I guess this is also an issue when type names are used in
non-constructor functions: e.g. should the to_str method actually be
called to_Str, should to_bytes be called to_Bytes ?
I think the "new" convention looks OK, but it is a bit weird with
multiple constructors in a module because you then have to include the
type name in the function name.
I am curious what the motivation is for changing the naming convention
of types?
There are two reasons that I can recall off-hand.
First, it adds some useful visual distinction. Rust code is anecdotally
easier for humans to read under this scheme.
Second, it helps to avoid an annoying problem with pattern matching,
where in-scope variants cannot be used as bindings.
enum foo {
bar
}
let myfoo = bar;
match myfoo {
// I want to bind myfoo to variable bar, but bar must be
// interpreted as a destructuring enum pattern
bar => #debug("%?", bar), // this is a compile error
};
// This is a more pronounced compile error. bar is a variant
// so cannot be used a pattern (or let) binding.
let bar = 0;
This error doesn't show up too often, but when it does it's baffling and
frustrating.
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev