DEV Community

loading...

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

Collapse
brandiware profile image
brandiware

OK folks. Readability IS a sign of code quality - for sure. HOWEVER, that does not mean it is necessary to drop useful elements of any language. You can't assert "never use a knive!" simply because misuse of knives is dangerous and can be BLOODY.
It is interesting to note, how little the examples in this post are commented !

ALTERNATIVELY, consider focussing on more and proper commenting:

// Process the passed argument, ... the result of the ... calculation ... , ... if it is useful
if myVariable != nil {
//DoSomeUsefulStuff()
}

Now judge by yourself how well the else part reads if commented (of course with some context of the preceeding IF logic)

// Drop out of the function / procedure if the passed argument, ... the result of the ... calculation ... , ... is NOT useful
} else {
return “”
}

My personal summary on code readability: Do comment;