Loading ...
Sorry, an error occurred while loading the content.

Re: [extremeperl] Refactorings?

Expand Messages
  • Adrian Howard
    ... [snip] Okay... here s one. (I don t have my Fowler to hand, so please excuse me if I wander off the standard format :-) ... TITLE: HashBecomesObject
    Message 1 of 14 , Jul 30, 2002
    • 0 Attachment
      On Monday, July 29, 2002, at 04:02 pm, Rob Nagler wrote:

      > I'm trying to get an idea what people consider useful refactorings.
      [snip]

      Okay... here's one.

      (I don't have my Fowler to hand, so please excuse me if I wander off
      the "standard" format :-)

      ---

      TITLE: HashBecomesObject

      SYNOPSIS:

      Turn a hash that represents a separate entity into an blessed object
      that reflects it's purpose.

      $Tests->{$class}->{$method}->{num_tests} = 4;
      $Tests->{$class}->{$method}->{type}->{setup} = 1;
      $Tests->{$class}->{$method}->{type}->{teardown} = 1;

      becomes:

      my $info = bless {}, 'Test::MethodInfo';
      $info->{num_tests} = 4;
      $info->{type}->{setup} = 1;
      $info->{type}->{teardown}=1;
      $Tests->{$class}->{$method} = $info;

      MOTIVATION:

      Perl lets you quickly create complex data-structures out of
      hashes-of-hashes, often acting as simple collections.

      These can quickly become hard to comprehend, use and maintain.

      If a part of a hash-of-hashes (or a hash all by it's lonesome) makes
      sense as a separate entity, turn it into an blessed hash.

      This acts as a precursor to things like ExtractClass and allows
      HashAccessBecomesMethodCall for your new object (I'll leave
      HashAccessBecomesMethodCall, and the obvious ObjectBecomesHash as
      exercises for the reader :-)

      ----

      I'm tempted to stick up a perl refactoring wiki (or is there one
      already hiding in a corner somewhere?)... Anybody second the
      suggestion?

      Adrian
      --
      Adrian Howard <adrianh@...>
      phone: 01929 550720 fax: 0870 131 3033 www.quietstars.com
    • Stephen Nelson
      Seconded.... I ve been planning on doing that for way too long. ... [Non-text portions of this message have been removed]
      Message 2 of 14 , Jul 30, 2002
      • 0 Attachment
        Seconded.... I've been planning on doing that for way too long.

        Adrian Howard wrote:

        > On Monday, July 29, 2002, at 04:02 pm, Rob Nagler wrote:
        >
        > > I'm trying to get an idea what people consider useful refactorings.
        > [snip]
        >
        > Okay... here's one.
        >
        > (I don't have my Fowler to hand, so please excuse me if I wander off
        > the "standard" format :-)
        >
        > ---
        >
        > TITLE: HashBecomesObject
        >
        > SYNOPSIS:
        >
        > Turn a hash that represents a separate entity into an blessed object
        > that reflects it's purpose.
        >
        > $Tests->{$class}->{$method}->{num_tests} = 4;
        > $Tests->{$class}->{$method}->{type}->{setup} = 1;
        > $Tests->{$class}->{$method}->{type}->{teardown} = 1;
        >
        > becomes:
        >
        > my $info = bless {}, 'Test::MethodInfo';
        > $info->{num_tests} = 4;
        > $info->{type}->{setup} = 1;
        > $info->{type}->{teardown}=1;
        > $Tests->{$class}->{$method} = $info;
        >
        > MOTIVATION:
        >
        > Perl lets you quickly create complex data-structures out of
        > hashes-of-hashes, often acting as simple collections.
        >
        > These can quickly become hard to comprehend, use and maintain.
        >
        > If a part of a hash-of-hashes (or a hash all by it's lonesome) makes
        > sense as a separate entity, turn it into an blessed hash.
        >
        > This acts as a precursor to things like ExtractClass and allows
        > HashAccessBecomesMethodCall for your new object (I'll leave
        > HashAccessBecomesMethodCall, and the obvious ObjectBecomesHash as
        > exercises for the reader :-)
        >
        > ----
        >
        > I'm tempted to stick up a perl refactoring wiki (or is there one
        > already hiding in a corner somewhere?)... Anybody second the
        > suggestion?
        >
        > Adrian
        > --
        > Adrian Howard <adrianh@...>
        > phone: 01929 550720 fax: 0870 131 3033 www.quietstars.com
        >
        >
        > Yahoo! Groups Sponsor
        > ADVERTISEMENT
        > <http://rd.yahoo.com/M=228862.2128520.3581629.1829184/D=egroupweb/S=1705007181:HM/A=1155070/R=0/*http://adfarm.mediaplex.com/ad/ck/990-1736-1039-302>
        >
        >
        >
        > To unsubscribe from this group, send an email to:
        > extremeperl-unsubscribe@yahoogroups.com
        >
        >
        >
        > Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service
        > <http://docs.yahoo.com/info/terms/> .
        > .




        [Non-text portions of this message have been removed]
      Your message has been successfully submitted and would be delivered to recipients shortly.