When working on a project where in you have to add features to an existing code written by other members of your team, you may have encountered problems understanding parts of the code. Sometimes the problems are caused by codes not well commented or sometimes the codes are simply unreadable.
Take this code for example:
The code is well structured except for the fact that the variable name "x" doesn't explain its purpose. One of the conventions to follow in writing variables is that you must name your variables words that describe its meaning.
In this example, if the programmer intends to use the variable "x" for evaluating where the current user will be redirected, he may use a more meaningful variable like:
This way, the programmer who will maintain the codes could easily understand what your code intends to do.
Another thing is to write descriptive method names:
Instead of:
Use something like:
By writing readable codes, you can reduce the amount of comment lines in your code. A code having a large amount of comments means that the codes are not readable enough.
Readable Code = Maintainable Code
- switch(x)
- {
- case 1:
- ...//
- }
- ...
- public int calculate(int num1, int num2){...}
- public void fillList(){...}
- public int getSum(int num1, int num2){...}
- public void getStudentList(){...}
- Add new comment
- 13 views