That's because the Kotlin range is declarative: using it I explicitly say that I want to iterate over all values within the given range. I don't provide the instruction on how to iterate, like in Java. In Java, I explicitly order "you should check the condition then increment".
-
-
Prikaži ovu nit
-
Why explicit instructions are bad? Because they could be wrong. In this particular case, they are wrong. If `to` equals to Integer.MAX_VALUE my Java loop is screwed: we silently overflow. When I program imperatively I should think about such corner cases.
Prikaži ovu nit -
When I program declaratively, corner cases should be handled by library/runtime/framework/compiler. Anybody, but not me. Even if a compiler has a bug, once it's fixed it'll work for everybody. In an imperative style, fixing the bug in one place doesn't fix every other place.
Prikaži ovu nit -
And yes, it's not a theoretical example, this just happened to me. Under rare circumstances, IDEA code analysis was stuck in the infinite loop. Were it Kotlin, such a problem would never happen.https://github.com/JetBrains/intellij-community/commit/b56a1fc16d446c92528994e0d333cbfa9ade21cd …
Prikaži ovu nit
Kraj razgovora
Novi razgovor -
-
-
From my experiences using “for” keyword is not very idiomatic in kotlin.
- Još 1 odgovor
Novi razgovor -
-
-
Kotlin didn't make a nice from..to when from>to and uses downTo.. it would be elegant to support it
-
I'm not sure that changing the direction silently if from happens to be greater than to is a good idea. It could be a source of very unpleasant bugs. You should explicitly tell that you want the reversed iteration.
- Još 1 odgovor
Novi razgovor -
-
-
And you can even do it with only one line of code, and that's incredible !pic.twitter.com/YP9ogmD4bw
-
Novi razgovor -
Čini se da učitavanje traje već neko vrijeme.
Twitter je možda preopterećen ili ima kratkotrajnih poteškoća u radu. Pokušajte ponovno ili potražite dodatne informacije u odjeljku Status Twittera.