which one do you prefer/recommend or maybe another...
# codingconventions
m
which one do you prefer/recommend or maybe another alternative options to suggest? 1️⃣
Copy code
private fun AccountInfo?.isNotEmpty() = this != null && 
    id.isNullOrBlank().not() && 
    status.isNullOrBlank().not() &&
    something.isNullOrBlank().not()
2️⃣
Copy code
private fun AccountInfo?.isNotEmpty() = this != null 
    && id.isNullOrBlank().not() 
    && status.isNullOrBlank().not()
    && something.isNullOrBlank().not()
3️⃣ (linter will complain when exceeded the max length)
Copy code
private fun AccountInfo?.isNotEmpty() = this != null && id.isNullOrBlank().not() && status.isNullOrBlank().not() && something.isNullOrBlank().not()
1️⃣ 1
2️⃣ 4
e
1️⃣ but I would always use
!
instead of
.not()
3
✍️ 1
https://developer.android.com/kotlin/style-guide#where_to_break "When a line is broken at an operator or infix function name, the break comes after the operator or infix function name."
IMO good style regardless of whether you work on Android. because of Kotlin's optional semicolon, binary operators at the start of a line will be parsed as unary operators instead, and it will simply fail for inline function names
m
turned out after using
ktlint
, no. 1️⃣ will make
ktlint
complaint 😞 and suggesting us to use 2️⃣
e
?? ktlint should be suggesting 1️⃣ and warning about 2️⃣
running it here with 2️⃣, it says
Copy code
Line must not begin with "&&"
m
oops, looks like our ktlint rules is messed up with default intellij idea rules (maybe the obsolete one)