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

Re: [XP] Re: Duplication vs Intention Revealing code (was: Zen Refactoring)

Expand Messages
  • Chris Dollin
    ... Would it be worth splitting it so that the main code produces the uniform answers, and there s a final produce idiomatic map which turns eg fourty to
    Message 1 of 42 , Jun 1, 2005
    • 0 Attachment
      On Wednesday 01 June 2005 14:02, Jeff Grigg wrote:
      > --- Tony Byrne <yahoogroups@b...> wrote:
      > > Oh my deity, what have I started? :-)
      >
      > My *EVIL Twin* did it. ;->
      >
      > > JG> I can go on to bigger numbers, but I see duplication here:
      > > JG> - The two "base 10" numbers, used to separate "tens"
      > > from "ones".
      > > JG> - That "four" and "four-teen" and "four-ty" is duplication.
      > >
      > > Now that's a new insight for me! It never occurred to me to
      > > programmatically handle the appending of 'teen' or 'ty'. Mind you
      > > won't 'Fivety' be wrong?
      >
      > Actually, I just realized this morning that "fourty" is wrong; I
      > need to learn to spell. :-O But it handles fifty and all the
      > others correctly.

      Would it be worth splitting it so that the "main" code produces
      the uniform answers, and there's a final "produce idiomatic" map
      which turns eg "fourty" to "forty" and "oneteen" to "eleven"?

      --
      Chris "electric hedgehog" Dollin
      It's called *extreme* programming, not *stupid* programming.
    • Alex Chaffee
      ... One way I ve found to avoid this is to use IntelliJ s awkwardly named Replace Method Code Duplicates refactoring. It looks for all blocks of code that
      Message 42 of 42 , Jun 4, 2005
      • 0 Attachment
        On 6/1/05, Elizabeth Keogh <ekeogh@...> wrote:
        > I've extracted a method from a test, then applied the extraction to a
        > similar chunk in another test, but missed out one of the parameters which
        > made it different.

        One way I've found to avoid this is to use IntelliJ's awkwardly named
        "Replace Method Code Duplicates" refactoring. It looks for all blocks
        of code that have the same structure as the contents of the method,
        and replaces them with a call to that method. It's the natural
        successor to Extract Method -- perhaps a better name would be "Apply
        Method". It's not perfect, but when it works it's a thing of beauty.

        Yesterday it saved us from just the problem you mentioned. We tried to
        apply it and it *didn't* select the code we thought it would; it
        turned out we'd missed a parameter. Once we introduced that parameter
        it worked. If we'd been doing this by hand we'd have made your
        mistake.

        - A
      Your message has been successfully submitted and would be delivered to recipients shortly.