orafaaraujo
11/18/2020, 6:05 PMwhen
when you can go with a simple if
But I can’t find it now… Does anyone knows where is it?if (bla) {
...
} else {
...
}
Instead of
when(bla) {
true -> ...
false -> ...
}
Marc Knaup
11/18/2020, 6:12 PMorafaaraujo
11/18/2020, 6:15 PMwhen
really charm as well, I was just wondering in that specific caseMarc Knaup
11/18/2020, 6:17 PMorafaaraujo
11/18/2020, 6:20 PMif (revealsPassword) text else password
and using `import InputType.text`/`.password`Marc Knaup
11/18/2020, 6:23 PMpassword
.orafaaraujo
11/18/2020, 6:26 PMtext
and password
doesn’t really help hahaalex
11/18/2020, 7:37 PMwhen
easier to read in assigning expressions, especially if condition/action is not short.
Basically, if if
cannot be expressed as
val x = if (flag) then y else z
, I'd prefer when
.
Few weeks ago I found very big project with code linting extremes, such as "do not use if at all, use when instead". Can't remember if this rule was applied for all if
constructions or just an assinging expression though.Shawn
11/18/2020, 8:00 PMval result = when {
foo -> "true"
else -> "false"
}