Meet the standards for Informatica and Information Technology
-
Use meaningful names Use descriptive names for all identifiers (names of classes, variables and methods. Avoid ambiguity. Avoid abbreviations. Simple mutator methods should be named
setSomething(...)
. Simple accessor methods should be namedgetSomething(...)
. Accessor methods with Boolean return values are often calledisSomething(...)
, for exampleisEmpty()
. -
Class names start with a capital letter.
class Post
-
Class names are singular nouns.
-
Methods and variable names start with lowercase letters. All the – class, method and variable names – use capital letters in the middle to increase readability of compound identifiers, e.g.
numberOfItems
, also calledlowerCamelCase
. -
Constants are written in UPPERCASE. Constants occasionally use underscores to indicate compound identifiers (SCREAMING_SNAKE_CASE):
MAXIMUM_SIZE
-
Suffix exceptions with
Exception
.
class MyOwnException
- When calling methods or fields from the current class, always prefix them with
this.
.
this.firstName
this.doSomething()
-
Tests should be placed in a seperate folder. The folder should be called
test
. -
For methods of Unit Tests we use the following convention:
void methodThatIsBeingTested_howIsTested_expectedResult()
-
One level of indentation is four spaces.
-
All statements within a block are indented one level.
-
The braces for class method and structural blocks are on separate lines and are at the same indentation level, for example:
public int getAge()
{
statements
}
while (condition)
{
statements
}
if (condition)
{
statements
}
else
{
statements
}
-
Always use curly brackets in control structures. Curly brackets are used in if-statements and loops even if the body is only a single statement.
-
Use a space around operators (=, +, -, *, %, /).
int sum = 5 + 6;
double multiple = 5 * 6;
-
Don’t use a space between the method name and the opening parenthesis of the parameters.
-
Use a space between the parameters of a method, so after each comma.
public void method(int param1, int param2)
- Use a space between (operational) keywords like
if, while, for
and the opening parenthesis.
while (condition)
if (condition)
for (condition)
- Don’t use a space for incrementing and decrementing operators, for example:
number++;
- Use a blank line between methods (and constructors). Use blank lines to separate logical blocks of code. This means at least between methods, but also between logical parts within a method.
public int method()
{
return 1;
}
public int anotherMethod()
{
return 2;
}
- Add a blank line before a return statement.
public void method()
{
statements
statements
return;
}
Don't add a blank line if there is only one line within a code block (for example an if-block).
if (condition)
{
return;
}
- Fields should be declared in the top of the class, before constructor(s) and methods.
class MyClass
{
Fields
Constructor
Getters and setters
Methods
}
- Getters and setters should be bundled. So, for example, if we have two fields
name
andnumber
we would have:
public String getName()
{
}
public void setName(String name)
{
}
public int getNumber()
{
}
public void setNumber(int number)
{
}
-
Custom methods should be placed below getters and setters.
-
Enum constants should be on its own line.
public enum Currency
{
EURO,
DOLLAR
}
-
Put classes that belong to eachother in a package.
-
The root of your project should contain a package according to the following naming conventions:
com.nhlstenden.projectname
-
Don't use whitelines in your HTML.
-
Every nested tag should be indented.
-
Tags should be in lowercase.
<button></button>
- Don't use spaces around
=
signs.
<img src="image.png" alt="A black and white cat" />
- Use lowercase for your filenames.
index.html
about-us.html
style.css
- Don't place a space after opening a tag paragraph tag.
<p>I don't need a space</p>