I recall a discussion in the past about using func...
# codingconventions
d
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
kotlinx.coroutines docs propose this for writing tests:
Copy code
@Test
fun exampleTest() = runBlockingTest {
    // ...
}
But that’s a special case I guess…
👍 1
r
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.