On 30/01/14 14:09, Samuel Williams wrote:
I agree that it is syntactic salt and that the design is to discourage
mutability. I actually appreciate that point as a programmer.
w.r.t. this specific issue: I think what concerns me is that it is
quite a high burden for new programmers (I teach COSC1xx courses to
new students so I have some idea about the level of new programmers).
For example, you need to know more detail about what is going on - new
programmers would find that difficult as it is one more concept to
overflow their heads.
Adding "var" as a keyword identically maps to new programmer's
expectations from JavaScript. Writing a program entirely using "var"
wouldn't cause any problems right? But, could be optimised more
(potentially) if using "let" for immutable parts.
Anyway, I'm not convinced either way, I'm not sure I see the entire
picture yet. But, if I was writing code, I'd certainly get sick of
writing "let mut" over and over again - and looking at existing rust
examples, that certainly seems like the norm..
Inside the main rust repository:
$ git grep 'let ' -- '*.rs' | grep -v mut | wc -l
17172
$ git grep 'let ' -- '*.rs' | grep mut | wc -l
5735
i.e. there are approximately 3 times more non-mutable variable bindings
than there are mutable ones.
On 30 January 2014 15:59, Samuel Williams
<[email protected]
<mailto:[email protected]>> wrote:
I guess the main gain would be less typing of what seems to be a
reasonably common sequence, and the formalisation of a particular
semantic pattern which makes it easier to recognise the code when
you visually scanning it.
On 30 January 2014 15:50, Kevin Ballard <[email protected]
<mailto:[email protected]>> wrote:
On Jan 29, 2014, at 6:43 PM, Brian Anderson
<[email protected] <mailto:[email protected]>> wrote:
> On 01/29/2014 06:35 PM, Patrick Walton wrote:
>> On 1/29/14 6:34 PM, Samuel Williams wrote:
>>> Perhaps this has been considered already, but when I'm
reading rust code
>>> "let mut" just seems to stick out all over the place. Why
not add a
>>> "var" keyword that does the same thing? I think there are
lots of good
>>> and bad reasons to do this or not do it, but I just wanted
to propose
>>> the idea and see what other people are thinking.
>>
>> `let` takes a pattern. `mut` is a modifier on variables in
a pattern. It is reasonable to write `let (x, mut y) = ...`,
`let (mut x, y) = ...`, `let (mut x, mut y) = ...`, and so forth.
>>
>> Having a special "var" syntax would defeat this orthogonality.
>
> `var` could potentially just be special-case sugar for `let
mut`.
To what end? Users still need to know about `mut` for all the
other uses of patterns. This would reserve a new keyword and
appear to duplicate functionality for no gain.
-Kevin
_______________________________________________
Rust-dev mailing list
[email protected] <mailto:[email protected]>
https://mail.mozilla.org/listinfo/rust-dev
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev