The importance of coding standards ...
I've been doing work for the web now for close to 10 years. During my tenure as a code monkey I have been a part of many, many projects. When approached with an offer for work, they all seem to fall within one of the following categories:
- You are asked to engineer an end-to-end solution from the ground up.
- You are asked to take over a project because the original developer dropped off the face of the planet... and ran off with all the money.
- You are asked to work within a team of developers to fulfill a project's requirements.
From my experience, there are several key things that drive me out of my FUCKING MIND when it comes to team-based development, one of them ranks highest above all: no standardized coding practices.
Seriously, if you're a developer working on a team-based project, how many times have you found yourself reviewing the code and realizing that it looks as if was written by 5 different people? What do you do?
- Do you write your own blocks of code in your own standard, thereby contributing to the problem? As in, now it looks like 6 people people have contributed to the same file instead of just 5.
- When confronted with a different standard, do you try and adapt to it just for that specific block of code?
- Just wonder how they've gotten this far without running the project into the ground and killing each other?
- Or do you just attempt to rewrite the entire thing according to the standard which you are accustomed to? Which, when you think about it, probably isn't a great idea as it would just throw everybody else off.
Personally, I don't really care what your style or standard is as long as you have one that you follow CONSISTENTLY.
Nothing can slow a developer down more than inconsistent coding. For example, some people like to code like this:
if($foo == 'foo') {
die('bar');
}else{
die('omg');
}
Or in short hand:
if($foo == 'foo'):
die('bar');
else:
die('omg');
endif;
Or indented if there is only 1 line to execute:
if($foo == 'foo')
die('bar');
else
die('omg');
Or, like me, with plenty of open space to see where you are:
if($foo == 'foo')
{
die('bar');
}
else
{
die('omg');
}
Let's not forget this asshole, who's all over the fucking place:
if ($foo == 'foo') {
die('bar');
}
else {
die('omg');
}
You know, save for the very last example, I haven't a problem with any of these styles. By themselves, if used consistently, you pretty much know what's going on all the time while you're mulling about the code. This becomes a problem when you're tracking a bug and come across a file with ALL of these styles mixed together. I can't recall how much time I've spent trying to wrap my brain around something that should have been simple enough to understand.
Inconsistent code blows performance and efficiency right out of the water, especially on larger projects.
This article isn't about a specific project in my past or anyone in particular. I'm not here to name names or point the finger, but certain measures must be taken during the analysis and planning stages of a project where a consistent style of coding should be decided upon. How much whitespace to use and where to use it, where to place curly braces, naming conventions for functions, variables, constants, classes and, most importantly, DOCUMENTATION are all things that need to be covered.
This way, when Joe Coder wins a contract that's already half-way finished, he can pick up and run with it in a relatively short amount of time.
Even if you're starting the project and riding solo at first, a set standard will make future developers happier too. Who knows how many hands will touch your code during the lifetime of the software?
Personally, I tend to follow this standard in most of my projects. It's pretty straightforward and easy enough to wrap your head around. The key here is to be consistent when you can. It's understandable to wiggle around your personal standards when working on a team with little or none of their own. In these cases, just morph your style to match whatever you encounter until you find an appropriate time to discuss the problem with your teammates or PM.
You know, come to think of it, I could have just summarized this entire article with a single tweet.
"For FUCK's SAKE, people! Pick a coding standard for your project and STICK TO IT!!!"
Sorry for the rant, but I have no one to scream at. So, I'll just scream at the Internets instead. Yay! :D


