Table of Contents

Introduction

This is a general list of guidelines and best practices collected from a variety of sources (books, interwebs, personal experience). All of these are guidelines should be taken with a grain of salt

some very helpful sources:

General

Naming

Names should

Comments

Every time you write a comment you should feel guilty. This may sound radical but keep reading. If you write a comment you are basically admitting that you need to document a hidden concept or intention that you did not manage to express within your code. When you start writing a comment stop for a second and think hard if there exists a better way to express yourself within the programming language. This will not always be possible but here are a few points to consider:

API Documentation (Javadoc)

Public APIs should be well documented. But the above guidelines should be kept in mind. A comment like

public interface Person {
/**
* Get the birthday of the associated person.
*
* @return the birthday of the Person as Date. 
*/
public Date getBirthday();
 
....
}

adds NO INFORMATION to the API. It does however add unnecessary clutter.

What should be documented in a Javadoc API:

Example

A trivial example: Instead of doing

...
if (record.getDate().before(MIN_DATE) ) { // remove if too old
  remove(record);
}

do

...
removeIfTooOld(record);
....
 
private void removeIfTooOld(Record r) {
 if (r.getDate().before(MIN_DATE) {
  remove(r);
 }
}

your intention is now encoded in the language itself, a comment is no longer required.

Classes / Interfaces

Inheritance

Methods

Arguments

Testing

Exception Handling

Here are a few guidelines