News for hackers. Stuff that matters.
Re:Swift is like Kotlin by zem on Thursday May 18, 2017 @12:19AM (#14364780)
it's always confusing, in languages with ranges, whether the range includes the second boundary element or not. it's purely a matter of convention, after all. ruby has a..b and a...b, but even after years of using the language i have to look up which is which. a..<b and a..b is perfect notation - once you know the language handles both cases, a..<b is very clearly "the range of numbers from a, and remaining strictly less than b", and "a..b" is "the range of numbers from a up to and including b".

as for the "count - 1", it's not too bad because i find "inclusive" more intuitive than "exclusive" for the a..b notation, and that does make it explicit that you're not including b, but it's visual clutter in much the same way that having to iterate an array via "for i = 0 to len - 1" is.

Re:Swift is like Kotlin by throwaway91111 on Thursday May 18, 2017 @12:24AM (#14364802)
Why is it a..b instead of the logical a..=b or a..<=b?
Re:Swift is like Kotlin by ves on Thursday May 18, 2017 @01:51AM (#14365075)
You only need to know that the language handles one explicitly, since there's two choices, so you might as well take the (more common | uglier to express) case and give it the "cleanest" special syntax: no special syntax.
Re:Swift is like Kotlin by ptx on Thursday May 18, 2017 @05:13AM (#14365832)
"a..b - 1" can also be written as "a until b" in Kotlin.
Re:Swift is like Kotlin by Filligree on Thursday May 18, 2017 @01:40PM (#14369304)
Which is not as obvious. I much prefer a..<b.