https://kotlinlang.org logo
Title
d

diego-gomez-olvera

10/13/2020, 4:07 PM
I recall a discussion in the past about using function expression (
=
) with
Unit
. In general I favor avoiding this and other people also found it confusing. Do you know if there is any kind of official guideline about it? https://kotlinlang.slack.com/archives/C4GKV43N2/p1506416194000224
as @raulraja I expect expression functions to not have side effects
f

Fabian Braun

10/13/2020, 4:25 PM
kotlinx.coroutines docs propose this for writing tests:
@Test
fun exampleTest() = runBlockingTest {
    // ...
}
But that’s a special case I guess…
👍 1
r

raulraja

10/13/2020, 9:24 PM
In Kotlin expressions can have side effects and the only way to track them is using suspend. Suspend guarantees exceptions are handled but just an expression vs a block with a return it seems more of syntactic preference since Kotlin does not enforce it. In suspend you are forced to deal with it
In languages like Scala is recommended but I don't know what makes most sense for Kotlin. Kotlin suspend is also opt in for effect tracking, you can still do I/O and effects without suspend.