In Xcode beta 3, Swift’s half-closed range operator has changed from .. to ..<, adding a less-than-sign visually distinguish half ranges (up to but not including) from full ones (up to and including). The update enhances visual inspection, making a clear differentiation between half (..<) and full (…) ranges.
While I applaud the intent, I dislike the result.
I get how errors similar to those between assignment and equality operators (= and ==) might happen. But while the =/== operators act in distinct ways, the range operators are more closely related. They’re less likely to produce foundational mistakes, and easier to catch through normal inspection.
A few additional points:
- The new half range operator is ugly. It turns an elegant for i in 1..5 into a visually confusing 1..<5
- When used next to a 3-digit, it looks like ascii art: for i in 1..<3 println(“Love you!”)
- Even without 3-adjacency, the new operator looks like an upside down deranged duck ..<
- The new operator requires explicit escaping on the web. (Thanks Andrew Wagner)
I’ve filed a radar. If you feel the same, consider adding one too.
As a final note, while this language tweak looks a bit like a literal duck, some are comparing it to the Coding Horror metaphorical one.
3 Comments
But you’ve got to admit the old .. vs … was a readability problem.
I’ve been reading the swift guide and readability is probably my biggest concern. Glad to see they’re working on that. Even if this one isn’t quite there yet…
It’s ugly but who cares. If it bothers you just use the range operator. It’s just syntax.
Just got onto the tutorials and this change got me. I must admit that while the two dots were more pleasing to look at than the new “..<" , I was kind of hoping that if we're going to go this route why not also have a version "<.." and "<..<"….. oh well