Refactor!

I’ve been refactoring code today. This is the programmer’s equivalent of a thorough edit: I’m not rewriting the story, just reworking everything so it’s clean and compact.

This is not my own code. It’s an application that we bought and are translating from one scripting language (PHP) to another (Ruby on Rails). I have to admit that I like refactoring, which I manifest by my copious complaints about all the mistakes the previous programmer made, his lack of style, his illogical choice of variable names, and so forth. It is SO much more fun to complain about someone else’s mistakes than it is to clean up after your own.

Refactoring is a great learning experience, because not only do I learn new things as I trace someone else’s way of approaching a problem, but I also reinforce all the things I know I ought to do in my own coding but sometimes neglect. A foolish consistency may be the hobgoblin of small minds, but a rational consistency is the savior of overworked developers — being consistent with things like naming patterns and formatting may not directly impact how code runs, but it sure makes it easier to follow along later. Patterns, my friends. It’s all about using patterns in your favor.

My biggest gripe is meaningless names for variables and functions. I mean, which makes more sense to you: “drawsel” or “drawSelectedEmotion”?

Yeah. I thought so.

Of course, this is all old hat to folks who are used to managing technical documents. We’ve all had to break someone of the habit of naming files “my proposal” instead of something that will actually be helpful when you’re trying to find a file, like “Beth - Pixar Proposal - Oct23 2007″ (I’ve never actually had cause to write a proposal for Pixar, but that doesn’t stop a girl from dreaming, eh?).

2 Comments »

  1. Tom Johnson said,

    October 24, 2007 @ 9:41 pm

    wow, I didn’t know you were familiar with PHP and Ruby on Rails to translate and clean up code. I’m impressed.

  2. beth said,

    October 26, 2007 @ 1:59 pm

    Yup. I love to code, and I find that programming typically leaves me more creative energy at the end of the day (for working on my novel, these days) than does creative work like designing sites and site graphics.

RSS feed for comments on this post · TrackBack URI

Leave a Comment