(Applicable to all java codes that is pushed)
- Classes and Interfaces :
Class names should be nouns, in mixed case with the first letter of each internal word capitalised. Interfaces name should also be capitalised just like class names. - Methods :
Methods should be verbs, in mixed case with the first letter lowercase and with the first letter of each internal word capitalised. eg.void changeGear(int newValue);
- Variables :
Variable names should be short yet meaningful.
Should be mnemonic i.e, designed to indicate to the casual observer the intent of its use. - Constant variables:
Should be all uppercase with words separated by underscores (“_”). - Javadoc:
These beautiful doc comments can be auto generated in VS code, given the java plugins are installed, and you press/** * Multiple lines of Javadoc text are written here, * wrapped normally... * @param: * @return */ public int method(String p1) { ... }
/**/
over a function. - Same line parenthesis policy:
for (....) { // allowed
for (...) // not allowed {
- Proper spacing:
notice the difference. Proper spacing between the( )
blocks and also between operators, e.g+
,=
,*
for (int i = 0; i < n; i += 1) { // good
for(int i=0;i<n;i+=1){ // bad
- Tab over spaces:
Indent using tab of size 4. - Readable code:
"Code should be self-documenting, that is, your naming should make it obvious what something does". exmaple:public boolean shouldConsiderAbbreviating(List<String> someNames) { for (String eachName : someNames) { // notice how proper naming improves readability if (isTooLong(eachName)) { // notice how to check if name is too long, we have used a function to improve readablity return true; } } return false; }
- Break big functions:
- Reduce nesting: