Styles

Wednesday, October 26, 2011

If coding seems tedious, then there's probably a better way...

I have to admit that I hate writing repetitive code. I’m not using the word “hate” lightly here. Whenever I’m asked to write a particularly boring group of code, I have to listen to rock music just to keep my mind occupied enough so I’ll finish my task without excessively checking my e-mail, talking to others, etc. If it gets really bad, I’ll go out for a brisk walk to burn off some of my energy, just so I’ll be able to sit for the amount of time necessary to get the job done.

Luckily I get to avoid writing tedious code most of the time. Usually there are ways around it. Getting data from the database and loading it into an object can almost always be automated by using an Object Relational Mapper. Getting information from an object onto a web page can be automated by using reflection, iterating through the properties, and setting the fields automatically. (If you don’t know what that means, it’s OK, it’s not central to the point of this post.) I’ve even written my own programs that will generate JavaScript for me so I don’t have to spend as much time debugging it.

A nice benefit to my avoidance of boredom is that by automating the boring stuff, my code is almost always faster to write and less error-prone than the more tedious equivalent. It’s a win-win, right? Why don’t more programmers think this way? You will get a few programmers who won’t use ORMs or reflection because they’re slower to execute, but in most cases I’m not going to lose sleep over a few hundredths of a second. I think mostly programmers don’t automate the boring stuff because they focus on what they know rather than experiment with trying to do something faster. They seem to want their automation done for them. My question for everyone, then, is how do we motivate more programmers to be more creative in increasing their own productivity?

No comments:

Post a Comment