At 1pm today I looked at a piece of code I had written last week.

It was fully functional, but not as optimal as it could (or should) be. It wasn't nice to other groups resources, and it had grown somewhat gnarly and untidy even after perltidy's magic.

So I was faced with the choice of whether or not to refactor/rewrite the code, based on what I'd already learned about the problem.

Now, for me at least, this code was complex. It dealt with data structures that were tough for me to get my head around. So, rewriting it actually caused me a certain amount of fear... what if I got halfway through and discovered I'd made a bad choice ? What if it didn't make any difference ? Oh my god this code is untidy, the design is clearly flawed..etc...etc...

The point is, taking the step to walk past that fear and refactor the code was one of those choices that became easy once I decided to do it.

12 hours later (well, maybe 5 hours of coding) the program is shorter, good friends with Devel::SmallProf, and has taken a cut in runtime of a little over 50%. The subroutines are better structured, the data structure is clearer, and testing it is similarly easier.

I think this is the first time I've felt that fear, and wondered if anyone else had ever had the same epiphany ?


In reply to On the fear of re-factoring code by deorth

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.