re: If/else or just if? VIEW POST

TOP OF THREAD FULL DISCUSSION
re: The second one. Every time. For the early returns reason mentioned earlier. Since you're doing a return, the else is an anti-pattern. Also this th...
 

Totally! "else" at the end of an if/else chain is a trap awaiting someone changing the input then making a mistake in the if/else such that the new input falls into the old else that does the wrong thing. Scala has "match" and the compiler gives an error if you don't match everything that can come in. Putting in a wildcard match at the end, which is equivalent of a last 'else' in JS, reads as "okay I don't recognise this input so I am going to ignore it". That screams anti-pattern as being both inefficient and inexact.

code of conduct - report abuse