| Subcribe via RSS

Muscle Memory, Part 1: The Strain of Repetitiveness

September 3rd, 2009 Posted in Metaprogramming, Perl

Earlier this morning, I worked a bit on my (other) hobby. Specifically, I fired up my airbrush[1] and painted the road wheels for a WWII Soviet tank that I’m working on.

Ask any modeler who builds armor subjects (assuming you know any, other than myself) and odds are that the road wheels are their least-favorite part of the model. They’re numerous, and worst of all, they’re numbingly repetitive. For this model, I had a total of 36 wheels to paint: on each side of the tank there are 12 road wheels in 6 pairs, plus 3 pairs of smaller wheels that act as return-rollers (keeping the tread from sagging too close to the tops of the road wheels) for a total of 18 per side. For some tank designs, the wheels are fairly simple, smooth affairs that are easy to paint. These, however, had a lot of tight corners and angles that I had to work the paint into. To be fair, this is not the worst-case I’ve dealt with; some years back I built a Panzerkampfwagen 35(t), which sports a numbing total of 24 wheels per side. At least those wheels were easier to paint than this morning’s were.

But it got me thinking about repetitive activity, and how it crops up in my coding. Like most dutiful Perl programmers, I use the “strict” and “warnings” pragmas almost religiously. I even set up templates in editors when and where I can, to ensure that these are always present in my modules. (Well, the use of “warnings” is a little more recent, so I still have some older code on CPAN that lacks the pragmata.)

Some would look at my repetitive use of these, and point out the recent addition to CPAN, common::sense. In many ways, this is a useful tool. But it suffers from some drawbacks:

  • It isn’t part of the core, so it would be an additional dependency.
  • It includes features that are specific to 5.10, so if you’re trying to maintain compatibility for older Perls, it isn’t an option.
  • Most of all, it hides too much of what is being done.

That last point is the most salient to me (that, and the fact that I have modules being used by large-ish projects that are still using 5.6.1). People sometimes talk about “self-documenting” code, code that is very clear in its purpose just from reading it. Truly, a name like “common::sense” is pretty clear. What isn’t as clear is what the author defines as “common sense”, and whether that matches your definition of such. The pragma-module does do its thing fast and with less memory usage than loading the individual parts does. But the user has to ask themselves if their code is clearer and more self-documenting with or without it.

As programmers, we loathe repeating ourselves. We program our editors with cut-and-paste and macro-definition capabilities, just to save a few keystrokes here and there. But we also often find ourselves committing bug-fixes to our repositories with a commit-message that is some variation of “cut/paste error… oops!”

In reasonable, small doses, repeating yourself can be an acceptable thing. Some people in my hobby clean their airbrushes by just running paint thinner through until it comes out clear. But I disassemble and carefully clean mine after every use, even if I plan on immediately loading another color and using it again. A friend in my hobby club back in Denver once said that he does that for the simple reason that the 5 minutes or so that it takes lets him rest his mind and refocus his thoughts on what his next steps are going to be.

When I start a new module or application, putting in the repetitive parts (even if it means only loading a template and making small adjustments) helps me narrow my focus from the project as a whole, down to this one file in particular that I’m about to work on. So, maybe repeating yourself isn’t always a bad thing.

(Edit: This entry is not meant as a critique of common::sense, but rather an argument that repeating oneself is not always a bad thing.)

[1] Before anyone asks: no, I can’t do any custom work for your car or motorcycle. I lack the skill at this point, and my airbrushes are designed for working with model paints. The lacquers one uses for automotive work would be hard on the internal workings.

Leave a Reply