Thursday, April 8, 2010

Best Practices

Some of Industry followed best standards:
1) Use if("Value".equals(var)) instead of the usual if(var.equals("Value")),
this will avoid a null-check on var before calling the var.equals(), the result remaining the same.
Simple yet useful.

2) Try specifying the size of the java.util.ArrayList when creating it, anyways its gonna grow when you add more elements to it.

3) Comments - They talk not just about your class or method but yourself.

Never touch or write a java file without providing comments on why you are doing it. Please don't bring up the Check-in argument here. Everyone's time is precious, (I learnt this from our Architect - Tad) don't let someone waste their worthy time on becoming a Sherlock Holmes to find what and why you had done something.

4) Do not use a,b,c.... as names for the instances. They don't signify anything. Single character names should be restricted to iteration variables in 'for' loops (or sometimes not even that, if you are using for:each).

No comments:

Post a Comment