Originally Posted by
whiteflags
Style two. Things getting complicated?
bool maybe = condition;
if (maybe) ...
Though it's not always easy to pare down to bool, which is fine by me.
Some folks I work with would argue that the 'maybe' is superfluous and adds nothing to the code; I know this b/c I am always doing that (boiling down large, complex (IMHO needlessly so) if() conditionals. A twist on the above is like this (warning, off-the-top of my head code coming to illustrate a point):
Code:
// old conditional
if( (someVal > 6) && (someOtherVal <= 2) || (someState == STATE_FOO))
{
// do something
}
// often becomes:
bool shouldActionBeTaken(int someVal, int somOtherVal, machineState someState);
if( shouldActionBeTaken(6, 2, someState))
{
// take action
}
In any event I find in complex logic, boiling your conditionals down to a single state ( in your case, 'maybe') helps convey the intent of the code better than almost anything else.
One thing in this thread that cracked me up is someone going on about the virtues of using little whitespace and single-char variables to save disk space...if your drive space is so limited that you have little room for clean-reading source you have larger issues than just drive space...
By that estimation, you should never backup source, keep a VCS going, etc. I am (literally as I write this) in the middle of a 6 TB data backup...well "middle" might be a little generous but you get the idea...anyhow the bottom line in that while I have a LOT of source code on my various dev machines, all of it combined (as well as multiple copies that the VCS keeps) is less than any single data file I am backing up. Having single-character variables, minimal whitespace, etc would save me ~ 0.00000000001% of my drive