jQuery in Action, 2nd edition*
The moose likes Java in General and the fly likes Please guide me on steps to be followed to refine code before Code Review. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Please guide me on steps to be followed to refine code before Code Review." Watch "Please guide me on steps to be followed to refine code before Code Review." New topic
Author

Please guide me on steps to be followed to refine code before Code Review.

Monica. Shiralkar
Ranch Hand

Joined: Jul 07, 2012
Posts: 639
There will soon be a code review in our project. I have been asked to ensure that my code is fine in code review.
What all do we need to care in Code Review? I have listed some of the things I can think off which should necessarily be checked before the code review. I understand that there will be some points which will be good to have and other which are Mandatory. I am trying to first list the mandatory ones.

1) To check whether all classes and methods must have proper comments.
2) To check whether names of all variables,methods, class follow naming conventions.
3) To check whether nowhere Exception e is caught.
4) To check no class variables are public.

Please tell me are there any other mandatory things to be checked.

Thanks...
Wayan Saryada
Ranch Hand

Joined: Feb 05, 2004
Posts: 105

Are you doing this code review manually? You might also consider to use tools that can help you review the code. There are a lot of quality consideration that can be reviewed in a code. One tool that might help you is the SonarQube, take a look at http://www.sonarqube.org/ for example.


Website: Learn Java by Examples
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41621
    
  55
For a somewhat harsher, but very thorough, look at your code you can also use tools such as FindBugs. It doesn't check the source code, but tries to find areas in the code that might be problematic at runtime.


Ping & DNS - my free Android networking tools app
surlac surlacovich
Ranch Hand

Joined: Mar 12, 2013
Posts: 296

PMD can also be an option.
Also, in the start of the thread you defined both syntactic and OOP-related requirements.

4) To check no class variables are public.

This one looks to me like incapsulation rule of OOP. So you can check if you meet other OOP best-practices: correct usage of polymorphism (overload, runtime), abstraction, SOLID principles, etc, along with providing right comments in crucial places of the code.
Tim Cooke
Bartender

Joined: Mar 28, 2008
Posts: 969
    
  47

Monica. Shiralkar wrote:To check whether all classes and methods must have proper comments.

This one could be trickier to justify in a code review as the use of comments can come down to a matter of taste and personal preference. Some people think comments are a good thing. Others think they can be a smell (I'm in this camp).

As a general rule I will not write JavaDoc comments for anything other than for API's that are being used by people outside of my team. If I find myself having to write a comment to explain what a method does then that tells me that my method is poorly named and/or it's doing too much. Either way my code needs refactoring. If I find myself writing a comment to explain a block of code then that tells me I need to Extract Method and name the method something similar to what my comment was going to be.

As a more general bit of advice for code reviews. It may be worth finding out what kind of review is going to be performed on your code. Are they just going to take a cursory glance over the code looking for syntactic stuff such as naming and layout or is it going to be a full functional review? If it's a full functional review then get comfortable as it will probably take a while. I would not worry too much about it, just be open about your design and style choices and be prepared to take some constructive criticism and action points to carry out on your code afterwards.


Tim Driven Development
surlac surlacovich
Ranch Hand

Joined: Mar 12, 2013
Posts: 296

Tim Cooke wrote:It may be worth finding out what kind of review is going to be performed on your code.

No, I think OP will find that out after the first review. There are a lot of company specific and project specific rules, so just make sure the code does right job first, all minor details will be explained right after the review. The point of code review is to make sure your code conform the rules.
Monica. Shiralkar
Ranch Hand

Joined: Jul 07, 2012
Posts: 639
thanks all
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Please guide me on steps to be followed to refine code before Code Review.