I just configured IntelliJ to enforce the Kotlin s...
# intellij
g
I just configured IntelliJ to enforce the Kotlin style as detailed here: https://kotlinlang.org/docs/coding-conventions.html#configure-style-in-ide Maybe it's my history with C/C++, Scala, operator precedence, operator overloading, but I think it's important to: • Make the not-sign visible and • Not assume the reader has memorized the precedence table I normally do that with an extra space and some parenthesis like so:
Copy code
if ( !parts.hasGroup ||
     (parts.groupId != group.id) ) {
But Kotlin/IntelliJ Style Inspection wants me to write, which obscures the "not" and the parenthesis:
Copy code
if (!parts.hasGroup ||
    (parts.groupId != group.id)) {
Or maybe:
Copy code
if (
        !parts.hasGroup ||
        (parts.groupId != group.id)
) {
Which is huge, but readable. I guess I don't think this if condition deserves so much emphasis compared to the code it contains. I'd like to be able to write the first without error, or understand why my spaces are bad here.
m
I can see the not-sign even without the space. It’s just a matter of habituation. There is zero chance that any one code style will please everyone. BTW: That snippet needs to be refactored anyway. For example, you could give parts a function
isNotGroup(id)
.
r
I feel like your 3 snippets are more obscure than just:
Copy code
if (!parts.hasGroup || parts.groupId != group.id) {
One goal of having a Kotlin style is that most Kotlin developers would be used to read Kotlin code with this style. I don’t see the point in altering it too much, and these additional spaces/parenthesis feel like too much. I would also wrap that condition in a function or en extension, but that’s not the subject here