This repository was archived by the owner on Apr 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Code Convention
Khiem Ton That edited this page Feb 1, 2024
·
1 revision
- Use
snake_casefor naming. Example:user_id.
- Use
PascalCase. - Avoid using abbreviations that are not clear.
- Do not use prefixes when naming classes:
- Incorrect:
IUser,RepoUser❌ - Correct:
User,UserServiceImpl,UserRepository✅
- Incorrect:
- Use
PascalCase. - Example:
UserService.java.
- Use
camelCasefor naming methods. Example:classifyStudent. - Method names should clearly reflect their functionality. Example:
calculateAverageScore. - Avoid vague or unclear names. Example:
- Incorrect:
display,calculate❌ - Correct:
showDetails,computeTotal✅
- Incorrect:
- Do not differentiate method names with numbers. Example:
calculateScore1,calculateScore2❌
- Use
camelCasefor naming variables. Example:int averageScore,String fullName. - Do not use prefixes. Example:
- Correct:
String address✅ - Incorrect:
String strAddress❌
- Correct:
- Variable names should be mnemonic, avoid unclear abbreviations. Example:
- Correct:
String address✅ - Incorrect:
String addr❌
- Correct:
- Do not name variables with just one letter like
x,y,z, except for counter variables likei,j,k. - Avoid overly long or short variable names as they can make the program confusing or the meaning of the variable vague.
- Only import necessary libraries. Do not use import-all.
- Example: Use
import java.util.List;instead ofimport java.util.*;.