Saturday 24 August 2013

Top Most Code Review Checklist and Best practices in Java

What to review while doing Code review
Code Review and Unit testing is one of best development practice I always recommend, strive for and enforce as much as possible. Even just by doing code review and Junit test case always offer positive result it can be improved a lot by constantly learning with our mistakes , others mistakes and by observing how others are doing it. I always try to get my code review by some one with more experience so that I can capture any domain specific scenario which has been missed during think through process and some with less experience so that he can improve his code readability, have a four eye check and most importantly I found that when i explain my code to some one as part of code review I myself discover many things which can be improved or left out.Overall it always add something and improve code quality and reduce bug.


code review checklist, code review best practicesI also review some one else code and voluntary take part to improve my code understanding ability and offer help to others, In this article I will list things which I look while doing code review. These are the things which I have been accumulated over the years but I also look forward to you guys to contribute your experience, best practices for code review and suggest how you guys do code review. These tips are independent of language and equally apply to Java, .NET or C++ code.

10 points checklist on Code Review


1) Does Code meet functional requirement: first and foremost does code meets all requirements which it should met, point out if anything has been left out.

2) Is there any Side effect of this change: Some time one change in your system may cause bug in other upstream and downstream system and it’s quite possible that new developer or anyone who is writing code might not be available of that dependency. This often directly related to experience in project and I found that the more you know about system and its environment better you able to figure this out.

3) Concurrency: does code is thread-safe? Does it have properly synchronized if using shared resource? Does it free of any kind of deadlock or live-lock? Concurrency bugs are hard to detect and often surfaces in production. Code review is one place where you can detect this by carefully understand design and its implementation.

4) Readability and maintenance:  does code is readable? Or is it too complicate for some-one complete new. Always give value to readability as code is not just for this time it will remain there for long time and you need to read it many times. Another important aspect is maintenance as most of software spends 90% time in maintenance and only 10% time on development it should be maintainable and flexible in first place. You can verify that whether code is configurable or not, look for any hard coding, find out what is going to be changed in near future etc.

5) Consistency: This is part of point 4 but I have made it another separate point because of its importance. This is the best thing you can have in your code which automatically achieves readability. Since many developer and programmer take part in project and they have there own style of coding, it’s in best interest of everybody to form a coding standard and follow it on letter and spirit. For example it’s not good someone using function initialize() and other is using init() for same kind of operation, keep you code consistent and it will look better, read better.

6) Performance: Another important aspect most important if you are writing high volume low latency electronic trading platform for high frequency trading which strives for micro second latency. Carefully monitor which code is going to execute at start-up and which is going to be executed in loop or multiple times, optimize the code which is going to execute more often.

7) Exception handling: Ask does code handles bad input and exception? It should and that too with predefined and standard way which must be available and documented for support purpose. I put this point well above on my chart while doing review because failing on this point can lead your application crash and not able to recover from fault on other system or other part of same application.

8) Simplicity: Always see if there is any simple and elegant alternative available at-least give a thought and try. Many times first solution comes in mind is not best solution so giving another thought is just worth it.

9) Reuse of existing code: See if the functionality can be achieved by using existing code, advantage of doing this is that you are using tried and tested code which reduce your QA time and also give you more confidence. Introducing new libraries introduce new dependency. I prefer not to try anything fancy until it’s absolutely necessary.


10) Unit test: Check whether enough JUnit test cases have been written and cover sufficient percentage of new code. never let you pass the code without Junit test because developer often make excuse of time but believe me its worth to write it.

Not last but least that put a comment on your java file that by whom it has been reviewed, what issue finds are out and status of those. This will make the whole process official and ensures that due diligence would be applied during code review. Its also good to maintain your own code review checklist or a project wise code review checklist and use it every time while doing review. There are so many best practices but I have only included those which I follow and found interesting but as I had said earlier this is the area which always needs improvement and no body is perfect on that. So please contribute your ideas on code review and effective development.

Enjoy

Some older post you may like

LinkWithin

Related Posts Plugin for WordPress, Blogger...

Labels

Core Java programming core java interview question Core Java Faq's Servlets coding database jsp-servlet spring Java linux unix interview questions java investment bank Web Services Interview investment bank mysql Senior java developer interviews best practices java collection tutorial RMI SQL Eclipse FIX protocol tutorial tibco J2EE groovy java questions SCJP grails java 5 tutorial jdbc beginner error and exception Design Patterns Java Programming Tutorials fundamentals general object oriented programming xml Java Programs Hibernate Examples Flex JAMon Java xml tutorial logging Jsp Struts 2.0 Sybase and SQL Server debugging java interviews performance FIX Protocol interview questions JUnit testing WebSphere date and time tutorial experienced java IO tutorial java concurrency thread Ejb Freshers Papers IT Management Java Exapmle Java Script SQL and database tutorial examples Scwcd ant tutorials concurrency example and tutorial future state homework java changes java threading tricky Agile Business of IT Development JSTL Java JSON tutorial Java multithreading Tutorials PM Scrum data structure and algorithm java puzzles java tips testing tips windows 8 5 way to create Singleton Object Architect Interview Questions and Answers Architecture Architecure Bluetooth server as swing application that searches bluetooth device in 10 meter circle and show all devices. You can send file to any bluetooth device. C Programming CIO Callable Statement in Java Circular dependency of Objects in Java Comparable Example in Collection Custom annotation in Java Developer Interview Divide and rule example in java Drupal Example of Singleton Pattern FIX protocol ForkJoin Example in Java 7 Get data from dynamic table with Java Script Git HTML and JavaScript Health Hello World TCP Client Server Networking Program Hibernate Basics Hibernate Interview Question Answer J2EE Interview Question And Answers J2ME GUI Program JEE Interview QA JMS interview question Java J2EE Hibernate Spring Struts Interview Question Java System Property Java Threads Manager Portlets Provident Fund Read data from any file in same location and give the required result. Reading Properties File in Java Redpoint Rest WebService Client Rest Webservice Test SAL join with ven diagram SCP UNIX COMMAND SSL Singleton Pattern in Java Spring Bean Initialization methods and their order Spring Interview Questions Struts Struts 2.0 Basics Struts 2.0 Design Pattern Submit Html Form With Java Script On The Fly Unix executable For Java Program XOM DOM SAX XP books computers core java; core java; object oriented programming data structure; java investment bank; design pattern dtd duplicate rows in table get browser name with jquery grails podcast inner class java beginners tutorial java cache java networking tutorial java spring java util; java collections; java questions java.java1.5 linked list mailto function with all browser oracle database oracle duplicate rows orm schema social spring mvc questions struts transaction tricks tweet windows xslt