|XP is just a number|
Re: Code Maintainabilityby kyle (Abbot)
|on Dec 03, 2008 at 23:01 UTC||Need Help??|
Thanks for your meditation. You've given me some food for thought.
I like statement modifiers for short statements.
For a much longer statement, I find the modifier gets lost, and it gets harder to understand what's going on.
I think there are plenty of times—perhaps even most times—that I'd rather read "if not" rather than "unless". I've seen programmers use "unless" almost universally for error conditions, and that seems like a pretty good convention, but even then I think it depends somewhat on what's in the condition.
The other thing about statement modifiers is they make it harder to add stuff to the condition.
If it were written as three lines to begin with, I wouldn't have to go through so much trouble to add the one extra action.
Sometimes "maintainability" is about "editability" rather than "readability". Yes, statement modifiers allow you to get more on the screen, and it may flow more naturally before your eyes. Now insert some debugging statements. When it barfs on line 123, is that the stuff in the condition, or in the condition's result?
I don't always write "one thing per line", but I see its advantages.
As an aside, this looks clumsy to me:
I've sometimes written that as: