Commenting


The commenting in an application can be divided into two type of commenting-      1. External Comments – /**            a. These are extracted to HTML using a Java Doc tool.            b. These comments are supposed to tell the functionality of the code without getting into details of the code. Discussion of design issues is still valid though.      2. Internal Comments- /*           a. ...

Indentation


1. Spaces VS Tabs The author of this source code is using TABs not only for indenting, but also for aligning! That way his alignment gets messed up when somebody uses a different TAB size. The solution of this problem is to simply just use what ever you want for indenting, but use spaces for aligning. 2. Line Length Avoid lines longer than 120 characters, since they’re not handled well by many terminals and tools. 3. Wrapping Lines · Break ...

File Organization Guidelines


The following is just an introductory into the file organization in Java. 1. Files longer than 2000 lines are cumbersome and should be avoided. 2. Beginning comments –  /* * Class name * * Version info * * Copyright notice * * Author info * * Creation date * * Last updated By * * Last updated Date * * Description */ 3. Package and Import statements package com.package.sub-package; 4. Class comments as java docs. e.g.  /** *  This class is responsible for doing ….. */ 5. Class statement e.g. public class ClassName {}    /     ...

Keeping constants on the left


It is often said that when using null checks, or equating variables, the constant values must be kept on left hand side. Until now, I’ve believed that it is a myth. But today I sat down to peel out the truth. Why one should follow it? Lets take the following example, String var = null; now,  var.equals(“constant”) // NullPointerException “constant”.equals(var) // False, No NullPointerException This happens because the equals method is usually written to include the null check in it. ...

Code Quality


I am dedicating the next month or two to the quality of code. Being a programmer is not just about writing good code. Its also about writing your heart off. Writing some unbreakable stuff. Spread the word. We are gonna bring some quality into our codes. Stay tuned for some interesting stuff. Just for the record, I’ll be focusing upon Java code. Although, most code conventions will be generic.