Skip to content

Commit 27ec723

Browse files
Merge pull request #5 from leapfrogtechnology/java
Java Naming conventions
2 parents 0564f2f + 4f61537 commit 27ec723

17 files changed

+469
-3
lines changed

docs/java/classes.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
---
2+
id: classes
3+
title: Classes
4+
sidebar_label: Classes
5+
---
6+
7+
#### The following convention should be followed for `class` naming:
8+
9+
* Class names are generally nouns or nouns phrases, in title-case with the first letter of each separate word capitalized or **UpperCamelCase**. e.g.
10+
- **LeaveController**
11+
- **EmployeeRepository**
12+
- **AttendanceRecord**
13+
14+
* Test classes are named starting with the name of the class they are testing, and ending with Test. For example,
15+
- **LeaveControllerTest**
16+
- **AttendanceRecordTest**
17+
18+
* Class name should be designed with single responsibility principle, self descriptive and self documenting.
19+
20+
* Classes on various application layers should be suffixed with terms as given below
21+
- Controller
22+
- LeaveController
23+
- ReportController
24+
- Service
25+
- EmployeeService
26+
- LeaveCalculator
27+
- ReportManager
28+
- Models
29+
- Leave
30+
- Employee
31+
- Balance
32+
- Report
33+
- Utils
34+
- ExceptionUtils
35+
- ReportBuilder (*follows builder pattern while generating report*)
36+
- HTMLParser (*cases which includes acronyms, should be written as it is.*)
37+
- Repository/DAO
38+
- EmployeeDao
39+
- LeaveRepository

docs/java/effective-java.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
id: effective-java
3+
title: Effective Java
4+
sidebar_label: Effective Java
5+
---
6+
7+
#### Effective Java

docs/java/functions.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
id: functions
3+
title: Functions
4+
sidebar_label: Functions
5+
---
6+
7+
#### The following convention should be followed for `function` naming:
8+
9+
* Method names should contain a verb, as they are used to make an object take action. They should be mixed case, beginning with a lowercase letter, and the first letter of each subsequent word should be capitalized. Adjectives and nouns may be included in method names:
10+
11+
### verb
12+
```
13+
public int calculateRemainingLeaves() {
14+
15+
//implementation
16+
17+
}
18+
```
19+
20+
### verb and noun
21+
22+
```
23+
public String getFullName() {
24+
25+
//implementation
26+
}
27+
````

docs/java/interfaces.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
id: interfaces
3+
title: Interfaces
4+
sidebar_label: Interfaces
5+
---
6+
7+
#### The following convention should be followed for interface naming:
8+
9+
* Interface names should be capitalized like class names.
10+
* Generally, should be **adjectives** or **nouns**
11+
- *LeaveService*
12+
- *Approvable*
13+
14+
* Interface represents type or contract on what the public methods and properties have to support. While naming interface, make sure its implementating classes demonstrate a subset behavior.
15+
e.g
16+
- **HealthCheckService** interface can have implementing classes like **DBHealthCheckService** , **StorageHealthCheckService**, **NotificationHealthCheckService**
17+
- Try not to includes Prefix like **I** or suffix like **impl**

docs/java/logging.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
---
2+
id: logging
3+
title: Logging
4+
sidebar_label: Logging
5+
---
6+
7+
Logging runtime information in your Java application is critically useful for understanding the behavior of any app, especially in cases when you encounter unexpected scenarios, errors or just need to track certain application events.
8+
9+
In a real-world production environment, you usually don’t have the luxury of debugging. And so, logging files can be the only thing you have to go off of when attempting to diagnose an issue that’s not easy to reproduce.
10+
11+
### Logging Conventions
12+
13+
* For consistency, declare your logger as the first field (top of code) in your class and declare it as follows:
14+
- private static final Logger logger = Logger.getLogger(MyClassName.class.getName());
15+
The variable name should be "logger". The term "logger" makes for cleaner code while not reducing any developer's ability to understand the code.
16+
17+
* Never log private or sensitive information such as **user credentials** or **financial data**. The data which should remain private must not be logged.
18+
* Never log too much information. This can happen in an attempt to capture all potentially relevant data. Too many log messages can also lead to difficulty in reading a log file and identifying the relevant information when a problem does occur. Always use cross-cutting concerns, an _Aspect_, to log the entry and exit of a method.
19+
* Sufficient information must be provided in the logged message.
20+
An example of a log message lacking specificity:
21+
- Error! Operation Failed
22+
Always add more specific and identifiable message:
23+
- Error! File upload profile_picture.jpg failed for unitId: 2
24+
* Add context in the log message by including the **timestamp**, **log level**, **thread name**, **fully qualified class name** and the **method name** of the event. This information can be hardwired in the configuration for the logging-framework used.
25+
* Use appropriate **LOG Levels**
26+
* **FATAL**
27+
FATAL should be reserved for errors that cause the application to crash or fail to start (ex: JVM out of memory)
28+
* **ERROR**
29+
ERROR should contain technical issues that need to be resolved for proper functioning of the system (ex: couldn’t connect to database)
30+
* **WARN**
31+
WARN is best used for temporary problems or unexpected behavior that does not significantly hamper the functioning of the application (ex: failed user login)
32+
* **INFO**
33+
Use INFO to report results to Administrators and Users. INFO should contain messages that describe what is happening in the application (ex: user registered, order placed)
34+
* **DEBUG**
35+
Use DEBUG to report results to yourself and other developers. DEBUG is intended for messages that could be useful in debugging an issue
36+
**TRACE**
37+
Use TRACE only for tracing the execution flow. In general, trace-level logging should be used only for tracing the flow of execution through a program and for flagging particular positions in a program.
38+
39+
### Logging Libraries
40+
41+
* <a href="https://logging.apache.org/log4j/2.x/" target="_blank">Apache Log4j2 (recommended)</a>
42+
43+
* <a href="http://logback.qos.ch/manual/configuration.html" target="_blank">Logback</a>

docs/java/packages.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
---
2+
id: packages
3+
title: Packages
4+
sidebar_label: Packages
5+
---
6+
7+
#### The following convention should be followed for package naming:
8+
9+
The prefix of a unique package name is always written in **all-lowercase ASCII letters** and should be one of the top-level domain names, currently **com**, **org**,**edu**, **gov**, **mil**, **net**, or one of the English two-letter codes identifying countries as specified in ISO Standard 3166, 1981.
10+
11+
- Packages are all lower case to avoid conflict with the names of classes or interfaces.
12+
- Special characters are not allowed while naming packages, only alphanumeric.
13+
- Avoid reserve keywords
14+
15+
Subsequent components of the package name vary according to an organization's own internal naming conventions. Such conventions might specify on technical aspect or a feature aspect e.g employee, leave, department, project etc :
16+
17+
#### packaging by feature
18+
19+
- com.projectname.employee
20+
- com.projectname.leave
21+
- com.projectname.department
22+
- com.projectname.project
23+
- com.projectname.utils
24+
- com.projectname.common
25+
26+
#### packaging by patterns
27+
28+
- com.projectname.controller
29+
- com.projectname.service
30+
- com.projectname.models
31+
- com.projectname.factories
32+
- com.projectname.utils
33+
- com.projectname.repository
34+
35+
In some cases, the internet domain name may not be a valid package name.
36+
This can occur if the domain name contains a hyphen or other special character,
37+
if the package name begins with a digit or other character that is illegal to
38+
use as the beginning of a Java name, or if the package name contains a reserved Java keyword, such as "int".
39+
In this event, the suggested convention is to add an underscore. For example:
40+
41+
| Domain Name | Package Name Prefix |
42+
|--- | ---|
43+
|hyphenated-name.example.org | org.example.hyphenated_name |
44+
|example.int |int_.example |
45+
| 123name.example.com |com.example._123name |
46+

docs/java/tools.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
id: tools
3+
title: Tools and Libraries
4+
sidebar_label: Tools and Libraries
5+
---
6+
7+
### Formatters
8+
9+
* [Google java Style](https://github.com/google/google-java-format)
10+
11+
### Dependency Management
12+
13+
* [Gradle](https://gradle.org) (*recommended*)
14+
* [Maven](https://maven.apache.org)
15+
16+
### Testing
17+
18+
* [JUnit 5](https://junit.org/junit5/)
19+
* [Mock Tool](https://github.com/mockito/mockito)
20+
* [Code Coverage](https://github.com/jacoco/jacoco)

docs/java/variables.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
id: variables
3+
title: Variables
4+
sidebar_label: Variables
5+
---
6+
7+
#### The following convention should be followed for variable naming
8+
9+
* Variable names should be **noun** or **adjectives** and should be **camelCase**. e.g age, balance, employeeReport etc
10+
11+
* Variable names should not start with underscore _ or dollar sign $ characters, even though both are allowed.
12+
13+
* Variable names should be short yet meaningful. The choice of a variable name should be mnemonic, self descriptive and semantical
14+
designed to indicate its intention.
15+
16+
* One-character variable names should be avoided like i, j, k, m etc
17+
18+
* Variable name should be plural if that is a collections. for e.g **employees**, **leaves** represents a list.
19+
20+
* Variables names should be declared as per their types
21+
* Map/KeyValue pair should be declared as *keyToValue* and *valueByKey*. For e.g **ageByName** or **nameToAge**.
22+
* Set can be prefixed as *unique* before variable names. For e.g **uniqueNames**
23+
24+
* Instance variable should be camelCase of their class names.
25+
* employeeService is an instance of EmployeeService.
26+
* reportDao is an instance of ReportDao.
27+
28+
## Constants
29+
30+
* Constants names holds same conventions as variable except it should be **UPPER_CASE** separated by **(_)** underscore.
31+
* **AGE_BY_NAME**, **EMPLOYEE_REPORT**

docs/python/classes.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
id: classes
3+
title: Classes
4+
sidebar_label: Classes
5+
---
6+
7+
#### The following convention should be followed for `class` naming:
8+
9+
* Avoid inbuilt names.
10+
* Classes names should always be `PascalCase`. i.e. `MyClass`
11+
* Even if you are building datatypes based on inbuilt class use PascalCase. i.e. `MyDict(dict):`
12+
* Describe the class resposibility in name.
13+
* Custom Exceptions should always be named ending with `Error` i.e. `MyCustomError`
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
id: environment_and_dependency
3+
title: Environment Isolation and Dependency Management
4+
sidebar_label: Environment Isolation and Dependency Management
5+
---
6+
7+
#### Information on development environment and dependency:
8+
9+
##### Environment Isolation:
10+
11+
* System installed `python` should never be used for development. Isolate your development.
12+
* Any of the following can be used for python isolation:
13+
- [pyenv](https://github.com/pyenv/pyenv). **Recommended** as this supports local python install and multiple python versions.
14+
- [virtualenv](https://virtualenv.pypa.io/en/latest/). _Third Party_
15+
- [venv](https://docs.python.org/3/tutorial/venv.html). _Inbuilt_ `python -m venv`
16+
* Use `pip` for installing packages if not using `poetry`.
17+
18+
19+
20+
##### Dependency Management:
21+
22+
* [poetry](https://python-poetry.org/) is recommended.
23+
- If not `poetry` use `pip` with `requirements.txt`
24+
* You can use `setuptools` and `setup.py` as well for requirements handling. They **must** be used for installable modules.

0 commit comments

Comments
 (0)