Friday, April 07, 2006

 

Beyond Dick and Jane

I actually had fun for a few hours at work this week. It was a surprise.

Normally, I am required to write brain-dead-simple C++ code. I have to write the kind of code that any idiot we hire off the street can maintain. I can't use templates. I can't use exceptions. I can't use overloaded functions. I can't use multiple inheritance. I can't use abstract base classes. I can't use anything in the <algorithm> or <functional> headers. Basically, I can't do anything that might confuse people who haven't read past Chapter 4 of The Complete Idiot's Guide to Learning C++ in 24 Hours for Dummies.

I find this frustrating. I think it's like writing one of those Dick and Jane books. See Spot. See Spot run. See Sally. See Sally run. file.open(). file.write(data). file.close(). Yawn.

Some people think it is good to restrict oneself to a "sane subset" of C++. I disagree. I don't want to use complex features unnecessarily, but I have seen many cases where code would be much, much simpler if somebody would just use some simple templates or exceptions. Without its "advanced" features, C++ is not a very expressive language. People who aren't comfortable using those features really shouldn't be calling themselves C++ programmers, in my opinion.

On Tuesday afternoon, the boss gave me the green light to write something exactly the way I wanted to write it. We had a complex problem that we thought would be best solved by using templates, exceptions, and other "advanced" C++ features. So I did. I used exceptions. I used class templates. I used member templates. I specialized member templates. I even had to crack open a book to figure out some of the syntax. It was challenging, and I learned some new things.

I stayed until almost 11:00 PM that evening. I didn't want to leave. I created something I thought was beautiful. I even wrote some documentation to explain it to others, because I was proud of it.

Unfortunately, the code didn't stay beautiful. Wednesday afternoon, we decided the code needed to do more than what I had designed it to do, and I couldn't figure out how to add those features while maintaining the beauty. So it gradually changed from that wonderful ideal into prosaic Dick-and-Jane-style code.

But that's okay. For a few hours, I was free to follow my muse and to remember why I got into this business in the first place. Now that I'm the lead programmer for this product, I hope I'll have more opportunities to try things My Way.


Comments: Post a Comment

<< Home

This page is powered by Blogger. Isn't yours?