On Jul 29, 2014, at 8:35 AM, Tom <
th...@me.com> wrote:
> On Monday, July 28, 2014 2:50:55 PM UTC+2, Josh Brown wrote:
> Oops - sorry, accidentally hit the wrong combination of keys and posted too early.
>
> Would this make sense instead?
>
> for index in 1..=5 {
> println("\(index) times 5 is \(index * 5)")
> }
>
> Before I go to radar, I thought I'd ask and hear others' opinions. With this approach, range operators would be more symmetrical/balanced (I'm not sure what the word is) - ..< and ..=. What do you think?
>
> I think it's ok the way it is now.
I could live with it too, the way it is now, though it is not my preference.
There were at least two common complaints about the original operators: (1) they were too easy to confuse with each other, and (2) they would irk programmers who use Ruby, which uses the operators in the opposite way. Both complaints were not merely matters of taste; they were concerns about it being easy to make mistakes.
The current operators take care of (1). Josh's proposal (which I also suggested a while back and would prefer) would take care of (2).
> Try to see it like this:
>
> The closed range (2...5) is symmetric, as it includes the first value and the last value: 2, 3, 4, 5. This is reflected by a perfectly symmetric operator "...".
>
> The half-closed (half-open?) range (2..<5) is asymmetric, it includes the first value but not the last value: 2, 3, 4, !5. The asymmetry is consistently reflected by an asymmetrical operator "..<".
>
> If you really would use the "=" sign in the closed range operator you had to write "=.=". Not very nice ;-)
That's only if you assume that palindromicity of the operator is the only way to look at it. It happens to work for the current operators, but other possibilities also have reasonable mnemonics.
[The current way] x..<y and x...y
[Mnemonic] "..<" is asymmetric (and its meaning is clear), and "..." is symmetric (and easy to type). A drawback is that Ruby programmers might inadvertently type "..." to mean half-closed because that's still in their muscle memory from Ruby work they were doing ten minutes ago.
[Original Swift] x..y and x...y
[Mnemonic] As offered by Chris Lattner himself: "..." has one more character, indicating a range with one more element.
[Ruby style] x...y and x..y
[Mnemonic] The .. operator means closed range everywhere else, no mnemonic needed for that; in "...", the third dot "pushes" the last element out of the range.
[Alternate mnemonic] Three dots is an ellipsis, which means something is omitted.
[Josh's/my proposal] x..<y and x..=y
[Mnemonic] The operators have a parallel structure (partly why this version appeals to me): ".." means this is a range operator, "<" means the last element of the range is less than y, and "=" means it equals y.
[Yet another possibility] x..<y and x..y
[Mnemonic] ".." means closed range everywhere else. The "<" means the last element of the range is less than y. A drawback of this is that you could forget to type "<" when you should have.
--Andy