4 ms·
It's the correct design only if we assume that the design space didn't allow for a different return type. Kotlin for example offers toIntOrNull (https://kotlinl
by dthul 5y ago
It's the correct design only if we assume that the design space didn't allow for a different return type. Kotlin for example offers toIntOrNull (https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.text/to-int-or-null.html https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.text/to-...) as an alternative.
- josefx 5y agoA null doesn't contain any information about what went wrong and unless you religiously check your objects for null values at every turn you just turned a clear stack trace into a search for waldo at the international waldo impersonators meetup.
- dthul 5y agoNote that in Kotlin the return type is `Int?`, not `Int`. You can't forget to check for null because the compiler enforces it. To your first point: Another example in the design space would be Rust which works very similarly to Kotlin but returns more information in the failure case.
- zvrba 5y ago> Note that in Kotlin the return type is `Int?`, not `Int`. How does that fare with unnecessary boxing of primitives?