kotlin-koans icon indicating copy to clipboard operation
kotlin-koans copied to clipboard

Not quite perfect answer in "Object expressions" and "SAM conversions" online koans

Open praetoriandroid opened this issue 6 years ago • 0 comments

Sorry, if this is the wrong place - the issue is related to online koans (http://try.kotl.in), not these one. But I could not find the better place for this.

Online koans are really great. And "Show answer" button is very handy: it helps to check out, is your solution the best for the kotlin style.

But in two tasks below you give not quite perfect answers. The suggested solution for comparing two Ints is "y - x": https://try.kotlinlang.org/#/Kotlin%20Koans/Introduction/Object%20expressions/Task.kt https://try.kotlinlang.org/#/Kotlin%20Koans/Introduction/SAM%20conversions/Task.kt

It works well with your test data set, but it's really bad idea to do this if, say, x = Int.MIN_VALUE and y = -1. And of course the correct solution here is "y.compareTo(x)".

I understand that this is not related to the kotlin koans directly. But someone can use the wrong pattern and get a bug. So please fix this.

praetoriandroid avatar Jul 29 '18 23:07 praetoriandroid