This list a series of best practices in order to make the applications more maintainable and easy to understand.

Naming conventions

Prefixes in bundles

2 to 5 letters. abbreviation of your organization. All lower case.

Ex: rq, sys, cap, ...

Rationale: short since you will have to type it. almost unique to avoid conflict with another organization code in case both are deployed on the same platform. Lower case to ease the parsing (extract the prefix until the first capital which is the name of the property or entity.

Entity names

No dot, no dash. Underscore discouraged. Start by an Upper case.

Rationale: Upper case for passing of the full name. Entity name will be visible in scripts (Javascript), therefore dots, dashes will case problems.

Ex: Switch

Property names

No dot, no dash. Start by an Upper case

Rationale: same as Entity name

User action names

User actions should NOT include special characters and start by a lower case. Camel case is ok. It should be a verb.

Example: 

edit

Rationale: used in URL (browser) which is usually lower case. (Not sure why tough)

Operations names

User actions should NOT include special characters: no dots or dashes and start by an upper case. Camel case is ok. It should be a verb.

Example: 

Save

Rationale: distinguish from user actions. Consistent with SOAP naming.

JavaScript Best practices

Javascript best practices are designed to make the code easier to maintain, more readable and less error prone.

Formatting and indentation level

By default 4 spaces.

Statement termination

In javascript, lines may be terminated by a new line or a semi column. We recommend the semi column for consistency with Java.

Ex:

var name = "toto"
function titi() {
   return toto
}

or :
var name = "toto";
function titi() {
   return toto;
}

Strings

in javascript, you may use a single quote or a double quote for strings:

var a = 'toto';

or 

var a = "toto";

We recommend using double quotes for consistency with Java (and c#)

Numbers

double:

var price = 10.0

integer:

var quantity = 10;

bad as hell : do not use a leading 0. In javascript it means octal (base 8). Therefore 010 == 8

var quantity = 010;

Arrays

Do not forget the rather elegant notation in javascript:

var arr = ["first", "second", "third"];
Tags:
Created by Pierre Dubois on 2012/06/22 15:27
     
This wiki is licensed under a Creative Commons 2.0 license
XWiki Enterprise 9.11.5 - Documentation