Writing Clean Code
I admit, I have a bit of a maniacal attitude towards code structure and formatting. I definitely drive my team (of one smart programmer) crazy with my coding standards. Sorry for that dude...
(Quick aside: the above image is a screenshot of the winning entry for the 1998 International Obfuscated C Code Contest. It's a flight simulator that actually compiles )
To be clear, I'm not talking about good code; that's just way, WAY, too subjective of a discussion. No, I'm talking about structure, layout and, most of all, consistency.
I tend to take this approach from a maintainability standpoint. The way I look at it, I've spent too much time in my career wading through some seriously bad code; there's just no reason not to do better for those who come after me.
That's only a part of it though. I have to go through my code; no fucking way I'm going to mess with myself or my team.
On the other side though, we also have to write code on behalf of our clients. We give them code that they paid us to do so it's pretty much a foregone conclusion that the client is going to go through the code. If we hand them crap they're, obviously, going to think we suck. That's no good for anyone.
It seems like such an obvious thing to write good, clean and well formatted code, that it's a little surprising how much bad code is out there.
Apparently, I'm not alone. Going through Reddit the other day I came across an interesting discussion of the importance of read-optimizing your code; it was nice to see the rallying and discussion. All of this stemmed from a really good article, on Brendel Consulting going into the importance of good source code.
When you design a software system, database or data structures, you take into consideration its most common use case. For example, you organize your data differently when it is read frequently, but only rarely written to. You read optimize your data.
I am convinced that the same applies to source code. In almost all cases, source code will be read much more often than it is written. Who writes the source code? You. A function is developed over some limited time, and once it is done it changes rarely, unless being refactored or modified to accommodate some changed requirements.
And, of course, there's a great post on Coding Horror discussing the similarities between, of all things, programmers and chefs.
For software developers, working clean means constant refactoring. If you don't stop occasionally-- frequently, actually-- to revisit and clean up the code you've already written, you're bound to end up with a big, sloppy ball of code. If you forget to regularly clean up behind yourself, things get smelly. Working clean means following your nose and addressing those nagging issues before they become catastrophic.
In addition to working clean, cooks also spend a lot of time thinking about mise en place, how their cooking stations are arranged for optimal work.
It's just too important we make sure to write good code and there's just no reason not to do it. If nothing else, remember that as a programmer you're judged by your code. Are you a professional?