DEV Community


Discussion on: Write better code and be a better programmer by NEVER USING ELSE statements

moopet profile image
Ben Sinclair

It depends, but oftentimes yes, because an "else" is a sign that your function is doing more than one thing, and a lot of people's programming philosophy revolves around making functions only do one thing.

Thread Thread
opwernby profile image
Dan Sutton

I know - again: good for really simplistic stuff, but in the real world, if you make every function do only one thing, you have to have so many of them that your code becomes spaghetti. Besides, avoiding an else in one function simply means you have to move it to another, or use a case instead, which is a bunch of glorified else statements: if the program needs to decide a thing, it's going to need to decide it somewhere.