Friday, January 9, 2009

The Windmill of Quixotic Code

When you program, are you a perfectionist? Do you take to heart all the lessons you learned from your shelf of computer books - lessons like, "always make your code reusable"? Coming into my recent job, I truly felt like being that way was going to help me exceed all their expectations. I was going to give them the ideal code - a comment for every variable and function, everything in a class structure, no globals. Then I opened up the project I'd be working on for the first time, and saw a "goto".

What you learn when you leave school is that perfect code doesn't exist for large projects. It's a pie in the sky, and if anyone preaches it to you, they are trying to make themselves seem like better programmers than they probably are. In the actual "biz", you get three adjectives for computer software, of which you may only have two at any given time:

Efficient.
Good.
Cheap.

My workplace, EDAS, is strictly the first two, but even then there are tradeoffs between "efficient" and "good". I consider "good" programming to be modular, since new features only need to affect certain elements of the code. But nothing's as "efficient" as code created with a specific purpose. So we have to keep things about 50/50 if we want a good name in our industry. Sometimes that means a goto, or a global variable.

If you go into a project charging at windmills, you'll quickly find very little accomplished. Seek what is useful, not what is ideal. If you are a hobbyist, I encourage you to try everything in your code. Try all the things you've been told not to try, and attempt to figure out where they're most useful. You'll get an occasional geek on a soapbox telling you that your code's inferior, but if nothing else it will be YOU and not them that actually knows why something must be avoided, rather than doing so dogmatically.

This is a lesson I myself have learned, and thought neccessary to share. I wish I had fully understood it myself when I came aboard with this company. But, at least I'm doing a good job now, and luckily I unlearn as quickly as I learn.

No comments: