Welcome to Simple Programming
Comments
Are comments necessary?
Why?
What?
Comments are for people not for machines
Think about refactoring the code so that comments are not needed
Long Method
Try avoiding longer methods. Short methods are easier to read and understand for a developer who looks at the code
Ideal lines of code - 20
Methods with 5 lines of code, indicate that you are breaking up the code too much, making it harder to understand
Too Many Parameters
Avoid to many parameters in the method signature.
Ideal number of parameters (as per checkstyle static code analyzer) - 7
Keeping it less than 5 makes it easy to read and understand
Type Embedded in Name
Avoid embedding types to the variable names.
Some Bad Examples
listOfStudents;
mapOfStudents
String sStudent;
int iAmount;
Inconsistent Names
Many developers have trouble with naming the methods or variables with an efficient name.
Examples
Use lower case for packages
Use camel case of variables and method names
Avoid using ‘_’
Dead Code
Unused code? Or commented code? Delete is before you push to repository
Temporary Fields
Avoid using too many temporary fields in the code. If your class has too many temporary fields - time to refactor the code
Refused Bequest
A derived class does not honor the contract of the base class.
Example - Liskov’s Substitution Principle
Middle Man
If you have a class or method that just delegates the input to another class. It is time to remove that class or method and call the endpoint directly
Solution Sprawl
If you have too many classes to perform a solution, you might have solution sprawl.
Time to refactor the code
コメント