Repeated from my comment to one of the patches: Not all the way there, but a step in the right direction ] On Wed, Oct 14, 2009 at 2:46 PM, Markus Roberts <[email protected]> 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? > > > > > >
-- Rein Henrichs http://reductivelabs.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 -~----------~----~----~----~------~----~------~--~---
