If-else over ternary operator
We need to avoid very long lines that are using ternary operator, because it makes code very difficult to read.
Straightforward usage of ternary operator is OK, for example: String name = user ? user.getName() : "";
Here is an example, last line in a controller that decides what is going to be returned.
What if we want to refactor such a code? We first split it into if-else branches and then we figure out what is actually happening.
Last updated
Was this helpful?