11 Feb 2010 00:07
Re: Literate style, making code more readable or going overboard?
Richard <legalize <at> xmission.com>
2010-02-10 23:07:04 GMT
2010-02-10 23:07:04 GMT
In article <64b8ffb11002101259u53364ac1kdd24daa5aa54b269 <at> mail.gmail.com>,
Dale Emery <dale <at> dhemery.com> writes:
> For me, negation becomes more confusing when the expression involves
> relational and boolean operators. I know DeMorgan's theorem, of course, but
> I don't wanna hafta think about it. And if the expression includes multiple
> operators, parentheses, or unparenthesized precedence differences, I'm prone
> to mistkaes.
Yeah, nowadays I would apply Extract Method to a complex condition
to give it an intention revealing name if it was feasible.
The double negative comes up more often for me in real world code.
Example:
bool dontPrint = true;
// other stuff
if (someCondition)
{
dontPrint = false;
}
if (!dontPrint)
{
printDocument();
}
To me this is just horribly confusing because the name expresses a
negative and we have to negate the negative name in order to express
the positive condition. I've even see people do things like this:
if (dontPrint)
{
}
else
{
printDocument();
}
which just adds dead code to the mix in order to compensate for the
double negative.
I wrote up the "Reverse Boolean" refactoring for this reason:
<http://legalizeadulthood.wordpress.com/2009/07/14/refactoring-reverse-boolean/>
--
"The Direct3D Graphics Pipeline" -- DirectX 9 draft available for download
<http://legalizeadulthood.wordpress.com/the-direct3d-graphics-pipeline/>
Legalize Adulthood! <http://legalizeadulthood.wordpress.com>
------------------------------------
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/refactoring/
<*> Your email settings:
Individual Email | Traditional
<*> To change settings online go to:
http://groups.yahoo.com/group/refactoring/join
(Yahoo! ID required)
<*> To change settings via email:
refactoring-digest <at> yahoogroups.com
refactoring-fullfeatured <at> yahoogroups.com
<*> To unsubscribe from this group, send an email to:
refactoring-unsubscribe <at> yahoogroups.com
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/
RSS Feed