android/kotlin-guides

Be concrete about && and || at the beginning or end of a line

Opened this issue · 3 comments

I think Java prefers

if (condition1
    && condition 2
    || condition3) {

    // do something
}

This style would make sense to me in Kotlin as well, but I couldn't find anything regarding to that in the IJ Kotlin style guide or Android style guide. Note that there has been some discussion going on in the ktlint project what prefers

if (condition1 &&
    condition2 ||
    condition3) {

    // do something
}

pinterest/ktlint#168

Tragically (in my opinion), Kotlin forces you into the latter as otherwise things like

foo
+ bar

could be interpreted as

foo
unaryPlus(bar)

depending on what is in scope.

I thought we covered this somewhere but perhaps it was left ambiguous. Would be good to include.

That example doesn't actually apply to the binary boolean operators, but I see no reason to create archaic rules around which binary operators and types you're operating on so we'll normalize to end-of-line rather than start-of-line.

I agree that it's really sad. At least I have something else besides ktlint that I could reference. Thanks