News for hackers. Stuff that matters.
Re:Swift is like Kotlin by saghm on Thursday May 18, 2017 @12:37AM (#14364842)
As an alternative opinion, I personally hate when ranges are exclusive by default. In addition to it feeling somewhat unintuitive to me that I need to use range(0, 6) to include 5, it also makes downward ranges quite awkward, e.g. needing range(5, -1) to count from 5 to 0.
Re:Swift is like Kotlin by dbaupp on Thursday May 18, 2017 @12:54AM (#14364897)
Exclusive by default is designed to fit with 0-based indexing (0..length(v), instead 0..(length(v)-1)). That said, this thinking is less relevant in languages with iterators/ranges and doubly so ones that offer a way to explicitly, but abstractly, iterate over the indices of a vector/array.

On the point of downward ranges, you can often reverse the range explicitly, rather than swapping the endpoints, like reversed(range(0, 6)) or range(0, 6)[::-1] in Python (vs. range(5, -1, -1)). Of course, this isn't nearly as syntactically nice as range(5, 0)... but that comes with its own problems: automatically iterating backwards in ranges has been really annoying every time I've encountered it (mainly in R), requiring extra care and a pile of extra ifs and/or mins & maxs.

Re:Swift is like Kotlin by saghm on Thursday May 18, 2017 @11:02AM (#14367792)
I understand the benefits, I just personally don't prefer it. But this is just my subjective opinion.
Re:Swift is like Kotlin by enqk on Thursday May 18, 2017 @09:52AM (#14367171)
Right-Exclusive ranges are superior to inclusive ranges because they can represent empty ranges, which removes one rare degenerate case and not overemphasizing it.

Another benefit: creating a series of right-exclusive ranges from a sequence [a, b, c, f] is easy: [a, b) [b, c) [c, f)

Re:Swift is like Kotlin by Someone on Thursday May 18, 2017 @02:55AM (#14365323)
On the other hand, it's easier to determine the number of items in a range if it is exclusive; range(n, m) contains abs(m - n) items.

Also, inclusive doesn't allow you to specify empty ranges. That may mean having to add if statements to your code, making it uglier.

I would prefer using notations [m,n) and [m,n], even though that uses a notation used in mathematics for a set to specify a sequence.

Of course, one would want (m,n) and (m,n], too, then, but that first one probably would make parsing your language difficult.

Re:Swift is like Kotlin by mixmastamyk on Thursday May 18, 2017 @12:57AM (#14364914)
It's due to the zero-based indexing, right? In something like lua, that starts at 1, inclusive makes more sense.