https://kotlinlang.org logo
#codereview
Title
# codereview
s

Shawn

07/03/2018, 5:48 AM
maybe I’m missing some context but it seems like you could at least simplify it to
buttonRegister.isEnabled = ! (isEmpty(email) && isEmpty(password) && isEmpty(confirmPassword))
but
!
is a source of contention among a lot of developers since it’s easy to miss or forget to use
p

Pavlo Liapota

07/03/2018, 7:01 AM
At least you can write
Copy code
buttonRegister.isEnabled = if (TextUtils.isEmpty(email) && TextUtils.isEmpty(password) && TextUtils.isEmpty(confirmPassword)) false else true
😛 But I would prefer
Copy code
val emptyFields = TextUtils.isEmpty(email) && TextUtils.isEmpty(password) && TextUtils.isEmpty(confirmPassword)
buttonRegister.isEnabled = !emptyFields
But as was suggested using
isNotEmpty()
would be best.
BTW, @Ayden, shouldn’t you use
||
instead of
&&
, i.e. button should be disabled if any field is empty?
a

Ayden

07/03/2018, 7:03 AM
@Pavlo Liapota you are right. The button will be disabled when one of the field is blank.
6 Views