- Use
SnakeCasefor directory names. - Use a singular noun or a compound noun for directory names.
- If a directory structure requires multiple words, create subdirectories.
- Use
PascalCasefor class names. - Interface names should start with an
Ifollowed by aPascalCaseclass name. - Abstract class names should start with an
Afollowed by aPascalCaseclass name.
- Use
CamelCasefor class field names. - Field names should start with an underscore.
- Field names should give a clear indication of the field's purpose and of the object type it holds.
- Use
CamelCasefor method names. - Method names should be a verb or a verb phrase that describes the method's action.
- Getter methods should start with
get, unless they are boolean, in which case they should start withis.
- Use
CamelCasefor method parameter names. - Parameter names should give a clear indication of the parameter's purpose and of the object type it holds.
- Use
CamelCasefor variable names. - Use
UPPER_SNAKE_CASEfor static constants. - Variable names should give a clear indication of the variable's purpose and of the object type it holds.
- Use 4 spaces for indentation.
- Do not use tabs for indentation.
- Use blank lines to separate blocks of code.
- Curly brackets should be on the same line as the statement they belong to.
- Brackets should contain a single statement, unless the statement is a boolean or arithmetic expression.
- Avoid using curly brackets for single-line statements.
- Keep lines of code under 120 characters.
- Do not chain more than 2 method calls in a line.
- Do not nest more than 2 levels deep.
- Apply the single responsibility principle.
- Keep classes under 200 lines, if they are longer it is likely that they do not have a single responsibility or can be broken down into smaller classes.
- Do not use public fields, use properties instead (except for constants or the classes in the
luka.modularmap.client.configpackage). - Do not use static classes, use singletons instead (except for classes in the
luka.modularmap.client.eventpackage). - Do not use class nesting, use composition instead.
- The order of class members should be as follows:
-
Constants
-
Fields
Use fields without the
thiskeyword, unless it is not possible. -
Constructors
-
Properties
-
Methods (private, protected, public in that order)
Methods that override a parent method should be placed at the end.
-
- Apply the single responsibility principle.
- Keep methods under 20 lines, if they are longer it is likely that they do not have a single responsibility or can be broken down into smaller methods.
- Create separate methods for separate logic.
- Do not use static methods, use instance methods instead.
- Use
@Overrideannotation when overriding a parent method. - Apply defensive programming.
- Apply the DRY (Don't Repeated Yourself) principle.
- Apply the DRY (Don't Repeated Yourself) principle.
- Use annotations to provide metadata about the code (e.g.
@Override,@Nullable,@NotNull).
- Use
*Servicefor classes that provide a service. - Use
*Repositoryfor classes that provide access to a data source. - Use
*Factoryfor classes that create objects. - Use
*Builderfor classes that build objects. - Use
*Mapperfor classes that map objects. - Use
*Validatorfor classes that validate objects. - Use
*Converterfor classes that convert objects. - Use
*Handlerfor classes that handle events. - Use
*Listenerfor classes that listen for events. - Use
*Managerfor classes that manage objects. - Use
*Controllerfor classes that control the flow of the application.
- Single responsibility principle
- Don't repeated yourself principle
- Defensive programming