https://kotlinlang.org logo
Title
m

miqbaldc

06/17/2021, 10:59 PM
which one do you prefer/recommend or maybe another alternative options to suggest? 1️⃣
private fun AccountInfo?.isNotEmpty() = this != null && 
    id.isNullOrBlank().not() && 
    status.isNullOrBlank().not() &&
    something.isNullOrBlank().not()
2️⃣
private fun AccountInfo?.isNotEmpty() = this != null 
    && id.isNullOrBlank().not() 
    && status.isNullOrBlank().not()
    && something.isNullOrBlank().not()
3️⃣ (linter will complain when exceeded the max length)
private fun AccountInfo?.isNotEmpty() = this != null && id.isNullOrBlank().not() && status.isNullOrBlank().not() && something.isNullOrBlank().not()
2️⃣ 4
1️⃣ 1
e

ephemient

06/18/2021, 12:03 AM
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

miqbaldc

06/18/2021, 6:27 AM
turned out after using
ktlint
, no. 1️⃣ will make
ktlint
complaint 😞 and suggesting us to use 2️⃣
e

ephemient

06/18/2021, 7:26 AM
?? ktlint should be suggesting 1️⃣ and warning about 2️⃣
running it here with 2️⃣, it says
Line must not begin with "&&"
m

miqbaldc

06/18/2021, 8:07 AM
oops, looks like our ktlint rules is messed up with default intellij idea rules (maybe the obsolete one)