HowTo write nice code
From SONIVIS:Wiki
Contents |
Installing and Using Formatter in Eclipse
Please go to Page "Configure Eclipse" in order to adjust your settings.
Before you commit code the code has to formatted with "CTRL+SHIFT+F"
Use less instance & class variables - use more parameters and local variables
Instance variables should reflect the individual state of an object. That means they may be different on each instance and are accessible to the outside world by field access or get/set methods. Class variables represent a property of all instances of this class and are accessible like instance variables.
Using class and instance variables for storing temporary information that is not of any interest to the (class/instance) outside world and that gets written and read in different places all around the class is like creating spaghetti code - somebody has to know in which order writes and reads are used to work just to change one line of code in the class. And there is no possibility to see at method signature that some instance/class variable is changed. As a result a coder has to read and understand the whole class to be aware at which points variables get changed and in which order changes and reads are used to operate. So please use parameters and local variables and use class and instance variables only if there is no other possibility.
For the right use of local variables see Locals (Only) When Needed
Session handling
If you ever have to work with org.hibernate.Session (e.g. for queries that are not covered by DAOs) do not forget to call Session.close()!!
Using SVN-Keywords
The general element comment of a java class should include the description, the author(s), the current version and the date of last change. The authors must be included using the javadoc tag @author, version and changed date must be included using the javadoc tag @version. Since we are using SVN (Subclipse) you can use $Date$ and $Rev$ to include automatic version and date. More about svn keywords, automatic documentation can be found at Configure Subclipse. In addition very useful are tags like @see, @param, @return, {@inheritDoc}... ([1]). An example can look like this:
/**
* Super class for arbitrary {@link InfoSpace} metrics.
*
* @author FirstName Surname
* @version $Date$, $Revision$
* @param <ValueType>
* Type of this metric's value
*/

