https://kotlinlang.org logo
Title
h

Hullaballoonatic

01/21/2019, 5:41 AM
what is significant that prevents kotlin from allowing
..
operator to create descending ranges like
9..5
? Shouldn't it be somewhat trivial to put into the code to create one or the other based on the higher value? is it simply ambiguity?
g

gildor

01/21/2019, 5:42 AM
This is intentional decision. To avoid subtle bugs with ranges.
👍 2
h

Hullaballoonatic

01/21/2019, 5:43 AM
makes sense. if they were only used to make ranges with number literals, then it would probably be added functionality, but with variables, it becomes obscure
g

gildor

01/21/2019, 5:43 AM
yes, because of variables and functions, such as indexOf, which may return
-1
so: 0..indexOf(smth) you getting range:
0..-1
👍 1
h

Hullaballoonatic

01/21/2019, 5:44 AM
thanks for the explanation
g

gildor

01/21/2019, 5:44 AM
and now it safe, you just get 0 length range