This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Any defect in the attached code

 
Arun Chidam
Ranch Hand
Posts: 79
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI GUys,

Can you spot any issues on the below code apart from the one i spotted(in bold)...

 
Stephan van Hulst
Bartender
Pie
Posts: 4838
34
Chrome Netbeans IDE Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It looks like someone is already reviewing this code for you. Why do you want us to look at it?
 
Arun Chidam
Ranch Hand
Posts: 79
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stephan van Hulst wrote:It looks like someone is already reviewing this code for you. Why do you want us to look at it?



Yes it was me who reviewed the code, I want to know if anything i missed in my review???
 
Ulf Dittmer
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What kind of issues?
 
Stephan van Hulst
Bartender
Pie
Posts: 4838
34
Chrome Netbeans IDE Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And please just post the fixed code. Not much point it looking for mistakes in code that is obviously mistaken.
 
Arun Chidam
Ranch Hand
Posts: 79
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stephan van Hulst wrote:And please just post the fixed code. Not much point it looking for mistakes in code that is obviously mistaken.


Updated the fixed code....

 
Arun Chidam
Ranch Hand
Posts: 79
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf Dittmer wrote:What kind of issues?


i am looking for runtime error(if any)?
Also is there any better way of coding the sort method?
 
Stephan van Hulst
Bartender
Pie
Posts: 4838
34
Chrome Netbeans IDE Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, you can just make your Name class implement Comparable, and then use the Collections.sort() method.

I assume you're implementing your own sort method as an exercise though. Anyway, there are several things you could consider wrong. Your method

1) is destructive, it destroys the list you pass into it. This is not considered very wanted behavior.
2) discards names that are 'greater' than "zzz, zzz", and inserts this name instead.
3) creates new instances for each name in the list, and adds them to the new list. Why not add the names directly?
4) uses a do-while loop. Don't use do-while loops. Use while loops instead.

Your Name class implements equals() wrongly, and on top of that, it doesn't implement hashCode(). Read the contract for Object.equals() and Object.hashCode().
 
Arun Chidam
Ranch Hand
Posts: 79
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI stephan, thanks a lot for your comments....your reviews are very helpful
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic