File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Website for code reviews? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Website for code reviews?" Watch "Website for code reviews?" New topic

Website for code reviews?

Geo Gavin

Joined: Jan 31, 2013
Posts: 2
I am just starting to write Java programs. I wanted to know if there are websites where people reviews each others code and comment about do's and donts ... Books may help but I believe to master a skill you need to practice and get hands dirty. Help will be appreciated.

Thanks in advance.

I wrote a Money Dispenser program

I wanted to know if my approach is correct.

My idea was to write a code that will generate change dispensed for a given amount of money. - This is where logic resides which decides how much money in what unit is dispensed

Input $11.53
Output 1 - $10 bill, 1 - $1 bill, 2 - Quarters, 3 - pennies

------------- is the class that describes the dispensed amount (money in different form of units (penny, quarter, dollar bill, $100 bill etc )).

This is the class where main resides and accepts an input argument for amount we want to dispense.

Andy Jack
Ranch Hand

Joined: Nov 22, 2012
Posts: 257
I wish I was smart enough to understand your code the moment I saw it. Please describe your code in detail with comments. Nobody has the time to go through lots of code.
To see what it feels like if you were in our position, please describe the code below and tell me if there is a problem in it.

Makes sense ?

Java Newbie with 72% in OCJP/SCJP - Super Confused Jobless Programmer.
I am a "newbie" too. Please verify my answers before you accept them.
Joanne Neal

Joined: Aug 05, 2005
Posts: 3527
Geo Gaga wrote:I wanted to know if my approach is correct.

The first thing you need to do is to read UseCodeTags.
Andy has done this and you can see how much easier it is to read his code. People are more likely to help you if you make it easier for them.

Winston Gutkowski

Joined: Mar 17, 2011
Posts: 7772

Andy Jack wrote:please describe the code below and tell me if there is a problem in it.


Please DontWriteLongLines. I've broken yours up this time (line 57).



Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
Nam Ha Minh
Ranch Hand

Joined: Oct 31, 2011
Posts: 498

I have seen a code review website (sorry I don't remember its name). I think there are such sites out there. And I agree with other buddies, the most important in code review is making it easy to review. Don't post bulky code.

PM Me If You Want to get Urgent Help on Java Programming
fred rosenberger
lowercase baba

Joined: Oct 02, 2003
Posts: 11302

The first and only thing anyone should say about this code is that there are basically no comments.

There is no reason to look at anything else until that is fixed.

Just my 2-cents.

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Geo Gavin

Joined: Jan 31, 2013
Posts: 2
Thanks all for responses. I added comments and code is now formatted. Thanks for the suggestions.
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 38756
Now it’s formatted, let’s have a look at it.

And you realise you have already found the best place for code reviews?
Tina Smith
Ranch Hand

Joined: Jul 21, 2011
Posts: 171

I have a couple questions about the datatypes you've used in your code.

1. What is the reason behind choosing BigDecimal as the object to do the calculations from in ChangeComputer?
2. Why do you declare constants HUNDREDVALUE (etc) as a BigDecimal than use it as an Integer?

I think HUNDREDVALUE should be HUNDRED_VALUE to split the words out so it's readable. Not so bad in this case but imagine if a word could be interpreted two different ways with and without the space.
You are using int in DispenseAmount but BigDecimal in ChangeComputer - this is inconsistent.

On comments....
I don't see any comments in the code at the beginning of this post. Maybe what you meant is that you put them in your local copy? If so, can you either update or post your changes(I kind of prefer updating since it means less to scroll through but could also be confusing since a lot of the posts that follow are about no-comments) so that we can see what you see?
At work, I put a comment above every method to describe what that method does. I don't think that's necessarily required for getter/setter methods but it should be done for methods that do any logic. Then I can skim code and see at-a-glance what this method is supposed to do, rather than figuring it out every time. Picture yourself six months in the future. If you needed to tell someone what this code does and you had only 3 minutes to look at the code before describing it to them, would you be able to do it? Would you be able to make changes to the code easily? Use these as a guideline for how many comments to put in. For a beginning programmer, that's usually a lot of comments (at least it was for me).

Everything is theoretically impossible, until it is done. ~Robert A. Heinlein
I agree. Here's the link:
subject: Website for code reviews?