RE: Re: Refactoring wishlist
"Mark Miller" <[email protected]> Tue, 27 Sep 2011 10:35:31 -0700
| Newsgroups | gmane.comp.programming.refactoring |
|---|---|
| Message-ID | <[email protected]> |
Hi George, CodeRush (for Visual Studio) does all of these if-statement manipulations that youre requesting out of the box, except for 11: Ø 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. which doesnt seem like a refactoring to me, unless Im misunderstanding it. CodeRush also has refactorings to combine in-series or nested conditionals and split complex conditionals into multiple nested or in-series if statements, which can be interesting (in-series combinations require/produce identical child blocks). - Mark Miller DevExpress C# MVP @MillerMark 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/