DEV Community

Discussion on: Ditching the "else" Statement

Collapse
 
eljayadobe profile image
Eljay-Adobe

That's one of the commandments from the structured programming era of programming. Apparently some professors are still living in that era.

Collapse
 
jonrandy profile image
Jon Randy 🎖️

When I had that class would have been around '95

Thread Thread
 
eljayadobe profile image
Eljay-Adobe

That'd be about right. 1950s structured programming approaches, which were refined and formalized in the 1960s, being taught in 1995.

There are languages, like COBOL, where the language itself doesn't allow you to violate the one return statement. Fortunately, JavaScript is not COBOL.

Collapse
 
aminmansuri profile image
hidden_dude

Well it's interesting to explore WHY they stressed this.

In the Assembly language world having jumps all over the place was a real problem. In the grand scheme of evolution this was an important principle.

Of course higher level languages made this point moot (in my opinion). And in fact, returning early often saves you from having to deal with flags which are really a horrible programming style.