Re: Literate style, making code more readable or going overboard?
Richard <[email protected]> Wed, 10 Feb 2010 16:07:04 -0700
| Newsgroups | gmane.comp.programming.refactoring |
|---|---|
| Organization | multi-cellular, biological |
| Message-ID | <[email protected]> |
In article <[email protected]>, Dale Emery <[email protected]> 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: [email protected] [email protected] <*> To unsubscribe from this group, send an email to: [email protected] <*> Your use of Yahoo! Groups is subject to: http://docs.yahoo.com/info/terms/