Example of dealing with (crappy) legacy code

This morning, I happened to be looking over some of my early PowerShell code, written about a year ago if I remember correctly. My first impulse was to eliminate all evidence that it ever existed. The problem is, I published it online, and tracking down every person who ever viewed or downloaded the thing seemed like a daunting task.

So, I decided instead to make a project out of cleaning up this old code, using the tools and skills I’ve picked up in the last year. In particular, I’ll be using Pester to write a suite of tests for the code, and then I’ll be refactoring it from a single 300-line Advanced Function into much smaller, easier to understand units.

I’m not sure how much time I’ll have to dedicate to this, and it will be fairly slow-going since I need to try to document my thoughts and changes every step of the way. However, when it’s done, I hope that it will present an interesting read for anyone who’s had to maintain legacy code (yours or someone else’s), opened up the file, and thought, “WTF?!”

At any point, you can refer to the repository’s log file to see the complete history of what’s been done so far, including links to the commits and files referenced in each step.

Advertisements

About Dave Wyatt

Microsoft MVP (PowerShell), IT professional.
This entry was posted in PowerShell and tagged , , , . Bookmark the permalink.

2 Responses to Example of dealing with (crappy) legacy code

  1. Dave, would you consider showing a walk-through on Unit Testing in Pester on the PowerShell.org TechSessions webinars?

    Like

  2. Dave Wyatt says:

    If the scheduling is flexible, sure! I’ll check with Don about that. So far every one of the TechSession webinars has happened at 11am Pacific time, and I don’t think I could commit to being available for that in the middle of a business day.

    This would probably need to wait until after we finish updating the documentation and get Pester 3.0 released. It would be kind of silly to deliver a webinar using the latest features if the help files and wiki are still half wrong. 🙂

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s