Re: Fwd: Compiler Guided Refactoring.
J Arrizza <[email protected]> Wed, 3 Jul 2013 09:16:44 -0700
| Newsgroups | gmane.comp.programming.refactoring |
|---|---|
| Message-ID | <CAEyOLyBfwH6uD6Z5RxBmmne4NA90cpF6N6LGacJPmRTSz7Enyg@mail.gmail.com> |
You could add a "convert to const parameters" to your list. This conversion
is extremely simple to perform, low risk and the compiler generates
appropriate warnings to help you out.
For another refactoring, it all depends on how timing critical your code
is. IMO the biggest bang for buck is the void-void extraction.
Before:
... some other code
//do some thing
statement1;
statement2;
statement3;
...more code ...
After:
void some_thing()
{
statement1;
statement2;
statement3;
}
...some other code ...
some_thing();
... more code ...
The original "// some comment" is a "tell" that those 3 lines belong
together, at least in someone's mind. Usually the name of the function
becomes just an abridged form of the comment.
The compiler will warn you of anything that those statements are using but
haven't been extracted along with the statements. One of the beautiful
side-effects of this, is that re-used temporary variables (a code smell)
are nicely reported by the compiler.
The probability of introducing a bug AND no new compiler warnings/errors is
extremely low. There is no effect to the behavior of the system at run time
except for the timing change because of the function call overhead. You
could add "inline" to the function definition to mitigate, but there is no
guarantee the compiler will actually inline a function marked "inline", and
so there is an uncertainty as to what is actually being generated and run.
Why is this the best refactoring? Because eventually the overall design of
the code emerges, i.e. the forest emerges from the trees.
The next best is the void-const extraction. There are parameters to the
function, but they are all const.
The one after that is when there is a simple, primitive return code (e.g.
ints and bools) and all const parameters.
John
[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/