Mr Galoot
Jun 20, 2022

I sort of subscribe to this. As a rule of thumb, there is an else for every if. Too many people forget that and by adding an explicit else, it is making it obvious the alternative path has been thought about. That said, it can make for messy code. I personally also subscribe to the idea of a single exit point from functions, return statements buried in if statements can be missed. The only ah-hem exception to the single exit point rule for me are exceptions. All this stuff is very subjective though, the most important thing is be consistent with whatever rule you go with, even if the code you are working on does something you don’t like, write your changes following whatever conventions are there already.

No responses yet