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

210Re: [extremeperl] Re: I almost had a heart attack: you call that refactoring???

Expand Messages
  • Terrence Brannon
    Apr 2, 2005
      Rob Kinyon <rob.kinyon@...> writes:

      > That kind of thinking is a shallow solution to the problem of a
      > repeated section of work. What if the repeated code isn't the correct
      > formulation of the abstract solution?

      The repeated code can be in a sub like Jim said. The third time, you
      simply rework the *sub* so it works with all 3 uses. If you lollygag
      around and copy it, you might forget about it. Or someone else might
      come along and not know about it.

      In fact, I will say for large systems, the goal is to move to modules
      or "Business Objects" immediately. Almost nothing should be done in
      the "action" part of your code but calling Business Actions from
      Business Objects... ever.

      > I don't know what kind of parameters it will need or what kind of API
      > it will need the first or second times I use a piece of code. By the
      > -third- time, I have a much clearer concept and I can now refactor
      > with confidence.

      No, I don't agree and stated why above.

      > >
      > Don't have the kneejerk reaction of "Must never repeat code!"

      I work at a place where we have the exact same business calculations
      in easily 5 places in the code and probably 10. This happens because
      no one had a set of Business Objects to add functionality to. They
      simply went in and k0ded a solution to their problem. And someone else
      did. And someone else quit. And someone new came along and did it
      again. And someone else did it for the other product. And someone else
      did it inside of HTML::Mason.... and when I ask to clean it up, I get
      treated like that unwanted Bible salesman who interrupts your day on

      So yes, I have become very aggressive about this issue because it is
      easy to lose sight of repeated functionality in big systems where you
      are under time pressure.

      > Often, it is useful to repeat code initially so that refactoring is
      > more productive.

      Well, let's see. Jim + Terrence = 2 against.
      Rob N. + Rob K. = 2 for.

      We are in a deadlock.

      > On Apr 1, 2005 1:18 PM, Jim Keenan <jkeen@...> wrote:
      >> --- In extremeperl@yahoogroups.com, Terrence Brannon <bauhaus@m...>
      >> wrote:
      >> >
      >> > <quote url=http://www.extremeperl.org/bk/refactoring>
      >> > if a routine is used only in one place, you keep it private within a
      >> > find another use for it, you refactor all three uses so that they
      >> call
      >> > a single copy of the routine. In XP, we call this the Rule of Three,
      >> > [1] and basically it says you only know some code is reusable if you
      >> > copy it two times. Refactoring is the process by which you make the
      >> > code reusable.
      >> >
      >> > </quote>
      >> >
      >> > I don't think it requires 2 uses of
      >> > something to copy it. The second time you need something, you refer
      >> to
      >> > the initial use.
      >> >
      >> I agree. As MJD says, "Repeated code is a mistake!" My own personal
      >> rule of thumb: If you use the same code twice, put it in a
      >> subroutine. If you use the same subroutine in two different scripts,
      >> put it in a module.
      >> jimk
      >> ________________________________
      >> Yahoo! Groups Links
      >> To visit your group on the web, go to:
      >> http://groups.yahoo.com/group/extremeperl/
      >> 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.
      > Yahoo! Groups Links

      Carter's Compass: I know I'm on the right track when,
      by deleting something, I'm adding functionality.
    • Show all 17 messages in this topic