Re: Refactoring wishlist
"George" <[email protected]> Thu, 29 Sep 2011 02:39:28 -0000
| Newsgroups | gmane.comp.programming.refactoring |
|---|---|
| Message-ID | <[email protected]> |
Mark, Look for my challenge to you in the paragraph above my signature. CodeRush looks good. But I wonder if we are communicating, here. I didn't find the logic manipulations anywhere in a quick scan of the CodeRush documentation (http://documentation.devexpress.com/#RefactorPro/CustomDocument1480). For instance, where is "apply DeMorgan's Law"? E.g., change something like if ( !(a || !b) ) ... into if ( !a && b ) ... assuming it would also remove double negatives and extra parentheses. A search for "DeMorgan" in your online documentation came up empty. So here's your challenge: give me the link or admit that you were giving an overzealous sales pitch. I'd like nothing better than for you to lay me out on this one and have your product win the day, but I don't think you can. George --- In [email protected], "Mark Miller" <markm@...> wrote: > CodeRush (for Visual Studio) does all of these if-statement manipulations > that you're requesting out of the box, except for 11: > >From: [email protected][mailto:[email protected]] On >Behalf Of George >Sent: Monday, September 26, 2011 1:45 PM >To: [email protected] >Subject: [refactoring] Re: Refactoring wishlist > > I've done some awkward cleanup of if-statements lately. It's especially > frustrating to reverse the sense of relatively complex boolean conditions or > otherwise simplify their expression. Here are some refactorings that woul > help, roughly in order of difficulty. > > 1. Reverse the sense of a boolean expression. I guess this is just adding > "!(...)" around it. If someone was negating a single variable or method call > you'd want to avoid inserting extra parentheses. > If the expression already contained a top level "!" you'd want to remove > both. Leave the resulting expression highlighted and ready to apply another > refactoring. > > 2. Remove redundant parentheses is an expression. > > 2. Remove double negatives throughout an expression. > > 4. Distribute AND over OR (or OR over AND). > > 5. Change a boolean expression to conjunctive normal (or disjunctive > normal). > > 6. Apply DeMorgan's law to an expression. > > 7. Reverse the sense of a boolean variable. For instance, if I have a > variable named "missing" and I realize that everything reads better if it is > named "found", I need to rename it, reverse it's initial value, reverse any > assignments to it, place a not (!) in front of every use, and remove any > resulting double negations. > > 8. Switch the sense of an if statement's condition while reversing the then > and else clauses. > > 9. Change an if-then statement to an if-then-else statement or vice versa. > > 10. Switch the sense of an if statement's condition where the statement > contains only the then clause, ending up with an if-then-else. This might > require duplicating code unless the original then-clause ends with "return", > "break", or "continue". > > 11. Remove a simple "return", "continue", or "break" statement that is > nested under an if-then or if-then-else so that the return is done at the > end of the block. Of course a resulting simple "return", "continue", or > "break" at the end of the method should disappear. > > 12. The reverse of 10. Change an if-then-else at the end of a block to an if > with a "return", "continue", or "break", depending on context. > > If you can get both 8 and 10 done, they should probably be combined into a > single refactoring. Maybe other refactorings of refactorings could be done > to make these apply to problems programmers have as opposed to abstract > boolean manipulation. > > > > [Non-text portions of this message have been removed] > ------------------------------------ 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/