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.