On Jul 27, 2013, at 10:48 , Zoltán Tóth <[email protected]> wrote:
> Then the coder can drop the pattern part without making the wording weird:
>
> loop 10.times() { ... }
>
This syntax has always bugged me. I always read it as "send the message
'times' to the object named '10'" but 10 is an integer literal and integers
don't have behavior. The '10.times()' syntax makes it look to the reader that
he's observing a conversation with a number rather than a dictation of the
actions that 'self' is about to perform. I know Smalltalk and Ruby use similar
syntax but I feel like they're also wrong to do so. I like any of the
following:
for i in 1..10 {}
for i in range(10) {}
for _ in range(10) {} //if you don't care about the index of the iteration
for i in range(1, 20, 2) {}
all of which are more clear to me. Something as core as control flow should
have a simple syntax without object-oriented-looking, DSL-type cleverness.
I don't intend to start a debate on the merit of any the various syntax choices
but this thread made me want to assure at least one anti-'10.times()' opinion
was heard :)
> My motivation is actaully something different: I feel this order more
> intuitive. I during coding generally like to be able to write the code in the
> order that I think. When I want to write a loop, first I think about that I
> want to iterate over some collection. Only after that do I think about a
> suitable name for the loop_variable / iterator. I understand that most
> programming languages use the <pattern> <expr> order and that programmers are
> used to it, but I think to be be intuitive is more important than to be
> similar, especially for a new language.
I do agree with this. SQL has a similar issue:
FROM t SELECT x, y, z
makes more sense (and as such can get more context-sensitive help) than
SELECT x, y, z FROM t.
Microsoft's Linq gets this order right IMO. In fact, Linq is pretty awesome in
general ( http://msdn.microsoft.com/en-us/library/vstudio/bb397906.aspx,
http://code.msdn.microsoft.com/101-LINQ-Samples-3fb9811b ) although my opinion
is mostly academic there. Having language-level support for the notion of a
query would be incredibly useful to me (unifying local and remote collections).
-ipc_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev