by devchix · 5y ago · 0 comments
if ( unexpected = true )
branch;
do_expected_stuff
Caveat: ways to do things age. Maybe this is no longer true or even slightly advantageous, but so far it has served me.I also prefer 20 lines of simple pedestrian code to 2 lines of clever code. I remind myself that I write for the maintainers, who do not have the benefit of my resident knowledge when they encounter the code.
My rationale is that having done this, I'm left with a smaller combinatoric mental space to work within. Like "if the program counter has reached this point then I know for a fact that X, Y, and Z don't apply - the function would have exited early if they did". And that then means the remaining set of things I have to keep in my working memory is reduced, which makes life easier.
Is that similar to how you see this advice?