About Kent Cowgill
Articles filed under...
.vimrc 9-11 acme aging algorithm andylester array attitude autocomplete baggyshorts BEGIN bestpractices big bike bikeshop bilk birthday blog bmi body_composition botanicgardens broken bugs bulge bumbo burnout bus butterscotch buzz cache calculator camera catalyst catnip cgi chart chin chinups chiropracter claim clog cloud code codger comics community commute complaint confusion constant coo cooking coworker cpan css dad database datamodel datatypes dbi deal debugging design devin docs documentation dsl ebook error exercise exhaustion Exporter feature_creep filecache firstpost fitness flattire flat_tire formatting fundraising funny google google_maps gravatar grilling groceries harness hash helmet highlight history home houston html humor identity ie imager indirect internet ipod journal kate kettlebell keynote kids ladder launch lazy legacy lisa lisanne list logarithmic lolcat macbook-pro maintenance map maps matthew memories meta michaelmckenna modules mom money monger mongers montreal motivation movie mvc mysql nasty notation objects offroad old oops optimize orm ouch outrage ownership park patrick paw pdf perl perlcritic phb photos pictures pinch presentation presentations principles programming progress push pushups rabbits racecondition rain rant reader recipes refactor requirements review ribs ride route run_on_sentences shadow shake site sitting slides sneaky soda sony sore soreness sorting spacebar speed spike spring sprint sql sqlite squeaky squeal statistics subversion syntax tag tags talk talks tap tasteofchicago tasty teachers technorati test testing tests text textile tire trac traffic trail training treats trick tricks tweak tweets twitter twitterpated updates ups vandalism versioncontrol video vim vimrc walk warren weather weblog welfare wikipedia winter wisconsin wishlist work workaround workouts xkcd yapc yapcna2007 youtube yummy zap

A R C H I V E S

(16)
(3)
(4)
(2)
(4)
(11)
(1)
(1)
(3)
(2)
(2)
(10)
(5)
(2)
(3)
(4)
(9)
(21)
(3)
(3)
(1)
(6)
(4)
(1)
(4)
(3)
(2)
(1)

    Is Kent Cowgill Online?
    View Kent Cowgill's profile on LinkedIn
    Add to Technorati Favorites

    Recent Entries...

    Week 3, day 2 for push ups

    I'm posting a bit more than a day or two per post, hoping I ...

    Chin ups week 1 column 2, push ups week 3

    August 6: Push ups: 27 then 20 (wow these seem tougher than...

    Exhausting chin ups, continuing with push ups

    August 4: I'm really glad I took the opportunity to rest ...

    Logarithmic tag cloud

    It's been a while since I've posted anything technical. Pos...

    Weekend bike rides

    August 2: I got out on my bike today. I had to raise the s...

    Still week 3 for push ups, finishing week 2 for chin ups

    July 31st: Push ups: 27 then 19 then 19 (the last 5 of whic...

    Tough push ups, and easier chin ups? Oh, kettlebell, too!

    July 29th: The push ups day I'm dreading. I'm feeling mostl...

    Push ups exhaustion test, continuing on with the chin ups.

    July 27th: Exhaustion Challenge, push ups. 31. Kind of dis...

    Weekend Respite.... or is it?

    So I ended up buying a kettlebell and getting back on my bik...

    Gotta keep going - on with week 2

    July 25: Super tired today. Woke up very early, had a pedi...

    weblog | `web·lôg -läg |
    noun
    Another term for BLOG
    ORIGIN 1990s: from web in the sense [World Wide Web] and log in the sense [regular record of incidents.]
    blog | bläg |
    noun
    A web site on which an individual or group of users produces an ongoing narrative.
    ORIGIN a shortening of WEBLOG.

    Testing and Documenting Legacy Code

    Kent Cowgill

    &qidYou may have guessed by now, but I've taken up a particularly onerous gauntlet at my job. I'm afraid to touch any modules. But holy cow, do they need touching.

    What do we learn from Refactoring: Improving the Design of Existing Code ? Well, we learn that without tests, you can't refactor. Well, you can - it's really not wise to do so, however. It will be difficult to know if you've broken something or slightly altered a particular functionality.

    Of course, tests also help you prove what you've got is a set of modules that performs to their specifications - or in the absense of a specification - proving that the code does what it looks like it's supposed to do based on certain circumstance.

    Given that our codebase is huge, undocumented, and more important untested, I've come up with a few snippets of shell code to really move me pretty far forward with my task.

    First, to create a directory hierarchy to house all my new tests:

    
    for i in $(find . -name "*.pm")
      do touch $(echo $i | \
               sed -e 's/\./\/path\/to\/dir/' | \
               sed -e 's/\.pm$/.t/')
    done
    
    
    

    And to give the files some default content (it's ugly but it sorta works, YMMV):

    
    for i in $(find . -size 0)
      do echo '#!/usr/bin/perl' >> $i
        echo "" >> $i
        echo "use strict;" >> $i
        echo "use warnings;" >> $i
        echo "" >> $i
        echo "Test::More 'no_plan';" >> $i
        echo "" >> $i
        echo "use_ok( '`sed -e 's/\//::/' | \
          sed -e 's/\.t//'`' );" >> $i
      done
    
    
    

    These snippets, plus my previously mentioned vim tip are really getting me pretty fair along in creating a comprehensive test suite and a good set of documentation for all of our legacy code.

    Oh, and as a side benefit, I'm getting to know the modules pretty well while I'm at it :)

    Handy vim mapping

    Kent Cowgill

    I'm going through a lot of legacy code lately, and got tired of manually opening up the first legacy file I documented (to make sure I was following the same standard I had implemented - it's not quite in my long term memory just yet), scrolling through the tedious documentation, copying (or retyping(!)) the text into the file I was working on, etc.

    So, I decided to write a quick little mapping for that menial task.

    First step is to create a template for the POD I want to insert:

    ~/podtemplate
    
    __END__
    
    =NAME
    
    =SYNOPSIS
    
    =DESCRIPTION
    
    ...
    
    
    

    And then this helpful mapping in my ~/.vimrc

    
    " Automatically add a POD template
    " to the end of a file
    noremap ,ap maG:r ~/podtemplate<cr>'a
    
    
    

    Mnemonic: Add Pod.

    ... which is at least smart enough to set a mark at your current position, move to the end of the file, insert the contents of ~/podtemplate, and return to your saved position. Caveats: It's NOT smart enough to know if you've already set an 'a' mark, and it's NOT smart enough to NOT insert the template if there's already POD in the file.

    Main Page | Login

    Do you want to buy me ? Find more gift ideas at my wishlist