https://kotlinlang.org logo
Title
c

cbruegg

03/11/2018, 7:48 PM
Since
set(value) = ...
for custom setters on variable is also allowed, I'd say it's no problem.
Unit
is just a normal return type and value in Kotlin.
a

Andreas Sinz

03/11/2018, 10:12 PM
I know that it works, I'm asking whether the Kotlin Style Guide encourages to use expression body with a one-line Statement or not
c

Czar

03/11/2018, 10:24 PM
it's indifferent on the matter. Common wisdom says, use them when they fit, don't when they don't, always specify return type in public API.
g

gildor

03/12/2018, 1:46 AM
Our internal style guide suggests to always use body syntax for functions that return Unit
3
a

Andreas Sinz

03/12/2018, 10:21 AM
And thats why I'm wondering why people save 2 keystrokes (inside Intellij its one? additional keystrokes)
fun foo() = println("Hello World")
vs
fun foo()  { println("Hello world") }
just to be confused when
fun foo(customer) = updateCustomer(customer)
returns Unit when you expect some kind of Result
c

Czar

03/12/2018, 11:53 AM
because it's not in the official guideline and they have yet to stumble upon a problem caused by this.