is there a way to have a variable assignment with ...
# codingconventions
e
is there a way to have a variable assignment with
if - else
with the code indented based on the position of the
if
?
Copy code
val list = if(student != null && student.passing)
              getListForStudent(student)
           else 
              getStandardList()
m
elect: I prefer
when
to be used in this kind of situations:
Copy code
val list = when {
    student != null && student.passing -> getListForStudent(student)
    else -> getStandardList()
}
Pros: * Easy to add assertions in functions * Easy to add new conditions * No problem with indentation
e
intersting hint, thanks
🙂 1
c
I put the
if
on a different line myself:
Copy code
val a =
  if (foo) 1
  else 2
It's the best I've found so far
👍 2