Try to write self-documented programs: Use logical variable names and function names :
not : int x;
but : int studentCount;
Comments :
Use comments whenever something is unclear. Think that you are telling some other person about your code. (After a long time, this person might be you)
Coding Conventions :
int myInt ;
void myFunc() { …
Necessary Tabs and spaces in Blocks. (Theoretically you can write a long program in a single line)
not : int x;
but : int studentCount;
Comments :
Use comments whenever something is unclear. Think that you are telling some other person about your code. (After a long time, this person might be you)
Coding Conventions :
- Class names start with Capital
- Instance names, fields, function names start with lower, etc.
int myInt ;
void myFunc() { …
- Static Final variables are All-Capitalized
Necessary Tabs and spaces in Blocks. (Theoretically you can write a long program in a single line)
Use getter, setter, and is methods.
Self-checking classes
int getCount() ;
int setCount() ;
isEmpty() ;
int setCount() ;
isEmpty() ;
- Use main() almost in every class to check class functionality.
- You can make an expected output check, in order to verify changes in the class.
In highly coupled classes, consider to make inner classes.
Keep method definitions and scopes as short as possible. (For easy visualization and readability.)
Compiler-time errors are better then run time errors.
Keep method definitions and scopes as short as possible. (For easy visualization and readability.)
Compiler-time errors are better then run time errors.
Prefer Interface definition to Abstract Class
Use Java Container Library classes
List l = new ArrayList() ;
Map hm = new HashMap() ;
Set s = new HashSet() ;
List myStack = new LinkedList() ;
Not : abstract class X { abstract void f() ; }
But : interface X { void f() ;
Spelling problems in overriding ClassesBut : interface X { void f() ;
class X { void encode() { … } }
class Y extends X { void Encode() { … } } // Does not overload the method
class Y extends X { void Encode() { … } } // Does not overload the method
Use Java Container Library classes
List l = new ArrayList() ;
Map hm = new HashMap() ;
Set s = new HashSet() ;
List myStack = new LinkedList() ;
Posted in: