On Oct 14, 2009, at 2:46 PM, Markus Roberts wrote:
>
> This is a trial-balloon.
>
> At Puppet Camp we identified a number of code smells that
> we'd all like to see removed from the puppet codebase.
>
> However, manually removing them (with tests, code review,
> etc.) would be prohibitively burdensome for patterns that
> occur hundreds or even just dozens of times throughout the
> code. Instead, I'd propose wherever possible using
> automated refactoring and proving the transformation
> rather than worrying about individual cases.
>
> Here are two examples to make this more concrete:
>
>
> --------------------------------------------------
>
> s/defined\? (.+?) and \1( |$)/\1\2/
>
> In code like:
>
> unless defined? @foo and @foo and bar("baz")
>
> "defined? @foo and @foo" can safely be replaced with "@foo":
>
> unless @foo and bar("baz")
>
> Because:
>
> * Both evaluate to false/nil when @foo is not defined
> * Both evaluate to @foo when @foo is defined
>
> --------------------------------------------------
>
> s/defined\? (.+?) and ! \1.nil\?/! \1.nil?/
>
> In code like:
>
> while defined? @foo and ! @foo.nil? ...
>
> "defined? @foo and ! @foo.nil?" can safely be replaced with "!
> @foo.nil?":
>
> while ! @foo.nil? ...
>
> Because:
>
> * Both evaluate to false/nil when @foo is not defined
> * Both evaluate to "! @foo.nil?" when @foo is defined
>
> --------------------------------------------------
>
> So what is the community sentiment on this sort of refactoring?
I'm very comfortable with the idea of automated refactorings.
I personally disagree that these idioms qualify as code smell, since I
use them to avoid a warning (ruby -w is essentially entirely useless
if you don't tend to use this idiom).
I appear to be "unanimously" overridden, though, so I'll bow out of
that part of the discussion.
--
You can't wait for inspiration. You have to go after it with a club.
-- Jack London
---------------------------------------------------------------------
Luke Kanies | http://reductivelabs.com | http://madstop.com
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Puppet Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/puppet-dev?hl=en
-~----------~----~----~----~------~----~------~--~---