A Funny Java Flavoured Look at the World

Tuesday, May 16, 2006

Why you should use coding conventions

I have been arguing with my fellow programmer today about coding conventions.  The argument is based around the placing of the curly bracket he likes to do it like this
 
if (boolean statement)
{
    //do something
}
else
{
    //do something else
}
 
and I am now (I had to be made to do it to start with ) do it like this
 
if (boolean statement) {
    //do something
} else {
    //do something else
}
 
 
I think the curly brace argument is one that rages all over the uk, now I used to put the curly braces in the style of the first example because it's easier to see them match up but then our development team call a meeting and we had to choose one way or another but all stick to the same method.  We decided to go with what ever convention Sun recommended in their coding standards document  http://java.sun.com/docs/codeconv/ 
 
The real reason why I am making so much fuss about this is because when ever I have to read his code it looks different than compared to mine and means that the style of the code changes dramatically from class to class.  The reason I want to stick to a coding standard is so all the code looks the same and I can then just worry about what the code is doing rather than where the braces are.  I also thinks it's important to be coding to industry standards because if you change job then it's more than likely the new company will be writing code to the industry coding standards, so you might as well get in the habit now, the longer you leave it the harder it will be to change.  If you really want to stick to the standard I would recommend using checkstyle to help warn/nag you to change the code to fit the standards. 
 
Sun says code conventions are important because
 
 
• 80% of the lifetime cost of a piece of software goes to maintenance.

• Hardly any software is maintained for its whole life by the original author.

• Code conventions improve the readability of the software, allowing engineers to

understand new code more quickly and thoroughly.

• If you ship your source code as a product, you need to make sure it is as well packaged

and clean as any other product you create.

a more important point about all using the same curly bracket convention is that it means when I look at the code I won't have to go through it putting the brackets in the right place, whilst my fellow programmer is putting them all back the other way in an evil catch 22 situation.

 

0 Comments:

Post a Comment

<< Home