While working in any company we are not the only one who writes the code. Most of time we need to work on the code written by others or may be possible, some one ,earlier had written the code and you need to enhance them. so in that situation what should we do? what should be the better approach to write the code?
- code review is always developer-to-developer work it does not involve testing.
- As you don't tell tester what to test same way you can't to other what code to review?
- For enhancement purpose changes are made in code so you should always check the code precisely.
Some points worth to consider :
- you can't use System.out.println("") as you use in real world, you need to use log4j or slf4j.
- you can't use public static void main(String[] args) to test your class.
- You need to use Junit or Mockito like frameworks to write test cases.
- While Writing test cases don't write test cases only for positive scenarios, also consider negative scenarios (means constraints that can fail the test cases)
- some basic mantras from design patterns are: write codes on basis of interface instead of implementing classes , favor composition over inheritance, as these style favors abstraction and abstraction makes the code readable and understandable.
- First point to consider is, does your code fulfill the functional requirements stated by your client or senior delegate?
- Most of time changes are made in code then here you have to consider, does the changes made affect other part of code or does it breaks others dependency ?
- Does the code is readable ? as many developers will come and go and may work on same code. to practice this you can adopt some common approach like write few lines of code and ask your friend to review that and ask him can he understand the code.
- Focus on naming convention means name of variable and name of method should be self explanatory.
- Take care of comments in your code like may be there unnecessary comments or may be comments with unused code.
- Lots of time copy paste is performed so there may be repeated code with same logic or hard coded value. so you should take care of this.
- In every company or workplace there some standards are being followed so while writing the code we need to care of this because it brings consistency while coding.
- May be variable scopes is not defined properly for example : in monetary control you need to use BigDecimal but some may use int instead.
- May have used mutable objects where immutable objects need to use.
- Have not followed proper language contracts like not implemented equals() and hashcode() properly.
- We also need to look around thread safety, look around code for proper synchronization and dead lock because most of time it becomes tough to detect those and it creates problem in production.
- look around the code for standard exception handling , you should always take care of does your code handle bad input , because if your code fail to handle exception well then your application may crash.
- Don't try to reinvent the wheel by writing your logic or implementation if it is already well tested and proven , provided with your API and this increases the re-usability of code.
- All of first regular practice, learning and off-course Experience.
- The fundamentals of language you are learning or using in your work.
- Design patterns in terms of Object oriented concept.
- Transaction,Concurrency,Memory,Performance issues ==> these are so vital aspects and we learn these all with experience.
- Consistent coding , following best practices, look for software development process, Security aspects .
- Many more.....that you will learn when you became passionate about your work and you learning.
"KEEP LEARNING, HAPPY CODING, DON'T LEARN ONLY TO FULFILL YOUR NEED, DO SOMETHING FOR YOUR PASSION"
No comments:
Post a Comment