Java Code Conventions
Saturday, February 24th, 2007When writing Java code you must follow the Code Conventions for the Java Programming Language. It’s a document written by Sun back in 1997. Why should you read such an ancient (in computer science terms) document?
Code conventions are important to programmers for a number of reasons:
* 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.
Some people tell me that they cannot change their style, because that’s how they are used to coding. Fair enough. Do whatever you want when coding alone, in your home. But not in a professional environment. If you can’t be bothered, do us a favour and leave. Resign. Start selling popcorn. Whatever.
I have a serious problem working with people who commit Java code which looks like this:
public class persons {
public void PersonSave(persons p) {
package foo.bar.personUtils;
public static final String foo = "whatever";
whatever()
{
// do stuff
}
Seriously, please try to read the following piece of code found in a real life project. Does this look like Java?
if(e<0.0)d= -d;
if(d!=0.0)for(int i=0;i<dim;i++)this.n[i] = this.n[i]/d;
else this.tW.writeString("normalise: non simplex");
Object leftList = null, rightList = null;
try{ leftList = c.newInstance();}
catch(Exception e){tW.writeString("sort:error1 ");return null;};
OK, this style might have been good in an Obfuscated Code Contest, but it definitely does not get you going in the workplace.
Good luck