I've been coding for over 20 years now! (WOAH, do I feel old)
I've touched just about every resource imaginable under the Sun (too bad they were bought out by Oracle)
In the context of this specific example, I am using early out return for the purpose of demonstrating the Guard Clause. Else statement can be avoided, but not covered since the article only focuses to reduce if/else nesting.
However, there are some cases in where one has to use else conditions.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
If you are using early-out return statements entirely, then the "else" statements are never needed.
Another method I've done in the past for very large lists (this only works in a few languages)
switch (true) {
case a: stuff1; break;
case b: stuff2; break;
case c: stuff3; break;
case d: stuff4; break;
}
That's right! Some languages will allow switch/case statements to compare a static value to a set of expressions, instead of the other way around ;)
In the context of this specific example, I am using early out return for the purpose of demonstrating the Guard Clause. Else statement can be avoided, but not covered since the article only focuses to reduce if/else nesting.
However, there are some cases in where one has to use else conditions.