Académique Documents
Professionnel Documents
Culture Documents
___________________________________________________
Version 1.0
2
1 Introduction
1.1 Purpose of the document
This document provides process guidelines that needs to be followed to adhere coding standards and
the steps followed for the end to end screen generation in Branch channel application.
1.3 Scope
3
2 Introduction
2.1.1 Overview
Code must be formatted to agree coding standards. Coding standards keep the code consistent and easy
for the entire team to read and re-factor. Code that looks the same encourages collective ownership.
4
are multiple words in the name,
then you need to use Uppercase
for starting letters for the words
except for the starting word.
This is called as
lowerCamelCase
2.2.2 Class
Context independence. All the dependency should be passed as part of the constructor. If a class is
context aware and tightly coupled, testing with mock or stub is not possible.
Class size should not be more than 500 lines including comments. Reducing the class size ensures
easy maintenance and re-factoring of the code in future.
Value objects should be immutable with properly overridden equals, hashCode and toString. The key
difference between value object and entity is unique identity using primary keys. Value objects are equal
if all the fields are identical in two instances. But entities are equal only if primary key is equal.
Don't use return code. Instead use exceptions. Return type should be used to return computed values.
This will make method signature intention reveling instead of always returning int (status code) as return
value.
Method size should not me more than 10 lines. For few exceptional cases, it can be longer with reviewer
approval but limited to max 25 lines. Reducing the class size ensures easy maintenance and re-
factoring of the code in future.
Typically each private method does one and only one thing.
Minimize accessibility of members. Never make fields as public. Instead encapsulate and expose using
method.
All public methods should have javadoc.
Fields in Serializable objects are part of public API even when visibility is private. Make sure to add java
doc and add @serial annotation.
Limit number of loops and conditional chaining (for, while, if/else & switch) to one in a method.
5
2.2.4 Conditions and Loops
When index access is required, initialize size one time instead of invoking size() method for each
iteration in typical loop. For arrays replace size() with length.
Don't do nested loop or nested conditional chaining.
Most of the times switch can be replaced with polymorphism using interface as type. Use switch only in
factory methods and module entry points.
Use exceptions instead of return code. Provide getter method in exception class to retrieve error code
and translate to message for logging and notification.
Use exceptions only for exceptional conditions and not as a conditional construct.
By default use RuntimeExceptions because most of the exceptions are not recoverable and typically
logged and notified. Do not use printStackTrace() to print the stack trace to console.
An error should be detected and handled if it affects the execution of the rest of a routine. For example,
if a resource allocation fails, this affects the rest of the routine if it uses that resource. This should be
detected and proper action taken. In some cases, the 'proper action' may simply be to log the error.
Consider notifying your caller when an error is detected. If the error might affect your caller, the caller
should be notified. For example, the 'Open' methods of 'a file class should return error conditions. Even
if the class stays in a valid state and other calls to the class will be handled properly, the caller might be
interested in doing some error handling of its own.
Document all exceptions thrown by each method. Write test cases for all exceptions conditions.
Make sure to roll back during exception to avoid inconsistent state either in-memory or in persistent
store.
Make sure all resources and memory allocated are released in the error paths.
2.2.6 Generics
Eliminate unchecked warnings from compiler. If you can't eliminate a warning, and you can prove that
the code that provoked the warning is typesafe, then suppress the warning with annotation
@SuppressWarning(“unchecked”).
2.2.7 Enums
Use two field enum instead of boolean (e.g. instead of isBlocked boolean use enum state {OPEN,
BLOCKED}. Enum is intention reveling.
6
2.2.8 Thread Safeness
If global variables can be accessed by more than one thread, code altering the global variable should be
enclosed using a synchronization mechanism such as a mutex. Code accessing the variable should be
enclosed with the same mechanism.
If some objects can be accessed by more than one thread, make sure member variables are protected
by synchronization mechanisms.
It is important to release the locks in the same order they were acquired to avoid deadlock situations.
Check error code paths.
2.3.1 Indentation
Indentations should be filled with space characters. Tab characters cause different interpretation in the spacing
of characters in different editors and should not be used for indentation inside a JSP page. Unless restricted by
particular integrated development environment (IDE) tools, a unit of indentation corresponds to 4 space
characters.
is preferred over
<%=customer.getName()%>
There should also be space characters separating JSP comment tags and comments:
<%--
-
a multi-line comment broken into pieces, each of which
-
occupying a single line.
--%>
<%--
a short comment
--%>
7
2.3.4 Comments
In general, JSP declarations for variables are discouraged as they lead to the use of the scripting language to
weave business logic and Java code into a JSP page which is designed for presentation purposes, and because of
the overhead of managing the scope of the variables.
8
is preferred over
<% out.print( x ); %>
In this scenario, breaking up this page directive like the following is preferred:
<%-- all attributes except import ones --%>
<%@ page
...
%>
<%-- import attributes start here --%>
<%@ page import="java.util.*" %>
<%@ page import="java.text.*" %>
…
Just as with the page directive, if the length of a tag library directive exceeds the normal width of a JSP page (80
characters), the directive is broken into multiple lines:
<%@ taglib
uri="URI2"
prefix="tagPrefix2"
%>
Only tag libraries that are being used in a page should be imported.
9
Disparate declaration blocks Preferred declaration block
Indentation
Use an indent of 2 spaces, with no tabs. No trailing whitespace.
String Concatenation
Always use a space between the + and the concatenated parts to improve readability.
var string = 'Foo' + bar;
string = bar + 'foo';
string = bar() + 'foo';
string = 'foo' + 'bar';
When using the concatenating assignment operator ('+='), use a space on each side as with the assignment
operator:
var string += 'Foo';
string += bar;
CamelCasing
Variables and functions in JavaScript should be lowerCamelCased. The first letter of each variable or function
should be lowercase, while the first letter of subsequent words should be capitalized. There should be no
underscores between the words.
10
Semi-colons
JavaScript allows any expression to be used as a statement and uses semi-colons to mark the end of a statement.
However, it attempts to make this optional with "semi-colon insertion", which can mask some errors and will
also cause JS aggregation to fail. All statements should be followed by ; except for the following:
for, function, if, switch, try, while
The exceptions to this are functions declared like:
do {
// Statements...
} while (condition);
These should all be followed by a semi-colon.
In addition, the return value expression must start on the same line as the return keyword in order to avoid semi-
colon insertion.
Control Structures
These include if, for, while, switch, etc.
if
if (condition1 || condition2) {
action1();
}
else if (condition3 && condition4) {
action2();
}
else {
defaultAction();
}
Control statements should have one space between the control keyword and opening parenthesis, to distinguish
them from function calls.
It is strongly encouraged to always use curly braces even in situations where they are technically optional.
Having them increases readability and decreases the likelihood of logic errors being introduced when new lines
are added.
switch
For switch statements:
switch (condition) {
case 1:
action1();
break;
case 2:
action2();
break;
default:
defaultAction();
}
11
Instead of complex if else structure, switch statement must be used.
try
The try class of statements should have the following form:
try {
// Statements...
}
catch (error) {
// Error handling...
}
finally {
// Statements...
}
Functions
Function and method names
Functions and methods should be named in lowerCamelCase.
Function names should begin with the name of the module or theme declaring the function to avoid
collisions.
Function Declarations
There should be no space between the function name and the following left parenthesis.
Exception: If a function literal is anonymous, there should be a single space between the word
"function" and the left parenthesis "(". Otherwise, it can appear that the function's name is actually
"function".
Define optional arguments (using default values) at the end of the function signature.
Always attempt to return a meaningful value from a function if one is appropriate.
Function Calls
Functions should be called with no spaces between the function name, the opening parenthesis, and the first
parameter; spaces between commas and each parameter, and no space between the last parameter, the closing
parenthesis, and the semicolon. Here's an example:
foobar = foo(bar, baz, quux);
As displayed above, there should be one space on either side of an equals sign used to assign the return value of
a function to a variable. In the case of a block of related assignments, more space may be inserted to promote
readability:
short = foo(bar);
longVariable = foo(baz);
12