Trailing boolean operations

Allowing trailing || and && both for begining and end will make formatter cleaner

val res boolean =
    obj1.param1 == obj2.param1
    || obj1.param1 == obj2.param2

so you can do

val res boolean =
    || obj1.param1 == obj2.param1
    || obj1.param1 == obj2.param2

val res boolean =
    && obj1.param1 == obj2.param1
    && obj1.param1 == obj2.param2

// Probably

val res boolean =
    obj1.param1 == obj2.param1 ||
    obj1.param1 == obj2.param2 ||

val res boolean =
    obj1.param1 == obj2.param1 &&
    obj1.param1 == obj2.param2 &&

from the code standpoint it will be. IDEA for now complains about expressions that could be simplified

val res boolean = false
    || obj1.param1 == obj2.param1
    || obj1.param1 == obj2.param2

val res boolean = true
    && obj1.param1 == obj2.param1
    && obj1.param1 == obj2.param2

I agree this looks nicer, but I’m pretty sure it would introduce ambiguities, and would make parsing much harder. The current rule of thumb is that an expressions ends at the end of the line, until there is a “good reason” it shouldn’t, like an operator expecting another argument. I think that is just the price we have to pay in order to avoid semicolons.

2 Likes

I have no idea why why wan’t to make our lifestyle so much harder..

Code should be able to be read by humans, that computers can read them that is also great!

The whole decision to omit semicolons and returns that are optional bugs me a lot in kotlin.
It does make code look more messy to my eye…