Skip to content
This repository has been archived by the owner on Aug 5, 2021. It is now read-only.

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

Open
praetoriandroid opened this issue Jul 29, 2018 · 0 comments

Comments

@praetoriandroid
Copy link

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant