DEV Community

Cover image for Code Review Checklist for Java Beginners

Code Review Checklist for Java Beginners

Anshul Bansal on January 05, 2020

Checklists are always helpful! They provide a quick check to ensure consistency and completeness in carrying out a task efficiently and effectively...
Collapse
 
xanderyzwich profile image
Corey McCarty • Edited

Id suggest that constants files only be used if needed in multiple places and apart from reference to a single class. It the usage will always be in regards to a single class (or within a single class) then put the constants in that class.

Collapse
 
smartyansh profile image
Anshul Bansal

Thanks for pointing it out. I totally agree with you. Will update the article.

Collapse
 
pedroduarten9 profile image
Pedro Neto

Great article and guidelines.

I just don't agree with number 12 as I believe self-documented code is better code.
I think comments are really useful in very specific cases, where your code can't explain what you want to achieve. About the author and date, the VCS covers that part of the comment.

In number 16 I would just add a default case to every switch case for enums, it is a good practice and helps developers when they add a new value to the enum.

Keep going!

Collapse
 
smartyansh profile image
Anshul Bansal

Thanks @pedroduarten9 for pointing it out. I agree with you on both points.

However, on number 12 it is advised for Java beginners to add comments on class/method which helps in Javadoc, not on the code to explain. As you say - comments are really useful in very specific cases. I'll update the article to mitigate this confusion.

Cheers!

Collapse
 
meedeniyats profile image
Tharuka Sandaruwan

Thanks for the guide.
Regarding the number 17, I feel like the example looks not very valid eventhough the point is valid.

Collapse
 
smartyansh profile image
Anshul Bansal

Thanks for pointing it out. I've fixed it in the article.
Please have a look.

Collapse
 
aminmansuri profile image
hidden_dude

The code example is wrong.

In both cases new Person is executed and there is no object reuse. Except that the second example obfuscates escape analysis, so I'd argue that its inferior.

Collapse
 
smartyansh profile image
Anshul Bansal

Thanks for pointing it out. I've fixed it in the article.
Please have a look.

Thread Thread
 
aminmansuri profile image
hidden_dude

I still don't get what you're trying to show here.

Java won't optimize anything in these cases because you're adding the person object to a list, so its not a short lived object.

Thread Thread
 
smartyansh profile image
Anshul Bansal

My bad. I didn't give it much thought.
Thanks for help!

Collapse
 
omriyahoo profile image
Omri Ratson

Great post!
In Intellij the default formatting rules (point 3) make 4,9 and 10 redundant because it does them automatically.
In addition, in Intellij you can set the flags "Add unambiguous imports on the fly" & "Optimize imports on the fly" to save you some typing even before the formatting is pressed.
:)

Collapse
 
smartyansh profile image
Anshul Bansal

Thanks.
I totally agree with you. IDE (IntelliJ, Eclipse) provides built-in features for automatic formatting and cleanup.

Collapse
 
silentsudo profile image
Ashish Agre

Good suggestion on One-liners, one-liner code is difficult to debug.

Collapse
 
aminmansuri profile image
hidden_dude

8 looks more like C++ to me than Java.. Am I missing something?

Collapse
 
smartyansh profile image
Anshul Bansal

It is actually Groovy. May be I should add simple Java code as an example.

Collapse
 
aminmansuri profile image
hidden_dude

But this article is called checklist for JAVA beginners. Groovy is not Java.

Thread Thread
 
smartyansh profile image
Anshul Bansal

It is my bad. I code both in Java and Groovy. And I missed to change the example code before adding it to the article. However, I've updated it to Java already.
Thanks for pointing it out.