What do the good people here prefer? <https://twit...
# announcements
p
What do the good people here prefer? https://twitter.com/pablisc0/status/1091715054070874113 😁
s
I like to extract the complicated bool expression into a separate function that has a name that says everything. then it is not essential for everyone reading the code to understand the expression. only if you want to debug the expression you really need to lokk at it 🙂
that ofc only makes the problem smaller ^^ in the end I always put the operators at the end of the line, because when you put operators at the start of the line you need to be aware of which operators also exist in a unary form.
with
&&
and
||
it is irrelevant, but look at this:
Copy code
fun main() {
    val x = 5
            + 4
            - 5
    println("x is $x")

    val y = 5 +
            4 -
            5
    println("y is $y")
}
it will print out
x is 5
y is 4
p
Yeah, I totally agree that it's better to do composition of functional operations instead of a long ones. The only thing about comparing
+
and
-
is that these are actually "sugarized" functions in Kotlin where as
&&
are actually operators. That example is interesting, why does it do that? 🤔 (To the ide...)
s
it is the same as
Copy code
val x = 5
        4.unaryPlus()
        5.unaryMinus()
👍 1
m
I prefer
&&
and
||
at the beginning of each line because that way you see that logic faster and the operators are always at the same horizontal position rather than jumping a lot depending on the length of each line. I'm used to do the same with all operators but it took me days to notice that it led to wrong computations because Kotlin treated
+
and
-
as unary operators in the continuation lines without warning, which for me was quite unexpected. So in that case I either have to put them at the end or wrap everything into braces.