instead of modeling with data class or data struct...
# announcements
c
instead of modeling with data class or data structure.
s
as a general rule, don’t write
$language
in
$other_language
c
whats wrong in that?
s
trying to mimic a feature from one language in another that doesn’t have native support for it often comes with disadvantages that aren’t always apparent
you can return a
Pair
or a
Triple
in Kotlin, but mimicking Go’s error handling is both a) not necessary and b) can be harder to read and work with in Kotlin
Pair and Triple both implement
componentN
functions, so you could destructure and have go-style syntax
Copy code
val (res, err) = doThing()
but then you’re stuck with endless
if (err != null)
when Kotlin provides better alternatives like sealed classes for something like
Result
or
Try
or just a nullable result that you can use monadically
and if you ever want to write code that other people will use or work on, https://en.wikipedia.org/wiki/Principle_of_least_astonishment