in reply to Re: Refactoring Perl 4 - Replace Temp with Query
in thread Refactoring Perl #4 - Replace Temp with Query
I certainly don't advocate for refactoring or following any particular guru advice merely for the sake of doing so. You are absolutely right that this example may appear unnecessary or counterproductive. If you found this to be the case in a particular example you ran into in the real world, I would expect that you would not choose to refactor.
Fowler discusses the upsides and downsides of refactoring in the early chapters of the book. If you find yourself interested in the details then, by all means, pick up a copy. Otherwise, please take these examples with a grain of salt.
This example may not be so good in part because it lacks context. As I mentioned in the OP, something like value of the $base_price temp variable is likely to be used in a number of different places in your code. As such, refactoring the definition of the base price actually limits rather than raises the potential for introduction of bugs by defining what base price means in one place. Again, context is the key, and the lack of context in some of these examples will undoubtedly cause confusion at times.
The upshot is that my goal here is to start with Fowler's examples and work from them. There will undoubtedly be cases where the examples don't necessarily translate well. This may be, in part, because I am converting examples in Java, where OO isn't a choice, to Perl, where it is. Or, it may be that an example that works well in Java doesn't work so well in Perl, despite the validity of the refactoing pattern. As such, issues like these will likely arise.
I am posting these examples to PerlMonks expressly to encourage discussion. So please don't take this reply (mine) as an admonition for silence. I would simply ask that y'all keep an open mind about it, take the examples with a grain of salt and keep the conversation going. I'm happy to be participating in this conversation about OO techniques in Perl.
perl -e 'split//,q{john hurl, pest caretaker}and(map{print @_[$_]}(joi +n(q{},map{sprintf(qq{%010u},$_)}(2**2*307*4993,5*101*641*5261,7*59*79 +*36997,13*17*71*45131,3**2*67*89*167*181))=~/\d{2}/g));'
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Refactoring Perl 4 - Replace Temp with Query
by mr_mischief (Monsignor) on Jul 31, 2007 at 18:58 UTC | |
by jdporter (Paladin) on Aug 02, 2007 at 18:34 UTC | |
by mr_mischief (Monsignor) on Aug 02, 2007 at 18:51 UTC |