Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

 

I highly encourage you to write down here all our coding conventions. From now on nobody will be able to say "how could I know?".

...

We add PluginName suffix only to classes that are meant to be used outside this plugin - things like: AwesomePluginConstants.java, AwesomePluginService.java.

Coding style conventions

Single line for or if statements:

Even if they are single commands that you are sure won't grow bigger we enclose it in { } brackets - always.

BAD

Code Block
if (condition)
  doSomething(); 

GOOD

Code Block
if (condition) {
  doSomething();
}  

 

We initiate objects, especially Lists (local - non field) upon creation:

Because if we won't we are in risk to letting them remain null.

BAD

Code Block
String name;

if (condition) {
  name = "Michael";
}  
Code Block
List<Entity> customers;

if (condition) {
   customers = loadCustomers();
}    

 

GOOD

Code Block
String name = "Name not available";

if (condition) {
  name = "Michael";
}    
Code Block
List<Entity> customers = new LinkedList<Entity>();

if (condition) {
  customers = loadCustomers();
}    

 

If we are dealing with 2 state enum kind of option we don't make the other option fall into simple else block.

Because number of states can change over time, and code where all different states fall into else block won't tell you anything, will just remain broken, silently.

This also applies to any options, not just model enums.

BAD

Code Block
// state is either 01draft or 02accepted
 
if ("01draft".equals(state)) {
  doSomething();
} else {
  doSomethingDifferent();
}   

 

GOOD

Code Block
// state is either 01draft or 02accepted

if ("01draft".equals(state)) {
  doSomething();
} else if ("02accepted".equals(state)) {
  doSomethingDifferent();
} else {
  throw new IllegalStateException("state is neither 01draft nor 02accepted");
}