This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

i dont know if this code is good  RSS feed

 
ekte spiriopoulos
Ranch Hand
Posts: 217
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the code is good? or there is a simpler coder about that?
 
Campbell Ritchie
Marshal
Posts: 55707
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For a start, the code is poorly formatted without enough space, not even lines between classes, and not enough indentation. You have only used one space per level.
Your variable names are poor; there are too many 1‑letter variables and some variables start with CapitalLetters.
Start by sorting out those concerns, so everybody can read the code.
 
John Pacuta
Greenhorn
Posts: 26
1
Android Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ekte,

It seems like little consideration was given in terms of the "code story". This code could be very useful for you but very difficult to debug. I'm going to step through your largest class, Quicksort.



Your question was if there was a simpler way. My question is, is there a way that tells a story of what is happening? Time, cost and utility all exist in a balance but I know the character "l" should never be used to represent a variable because of how syntactically weak it is compared to 1 and I. I know it seems very trivial, but the first person debugging your code will probably be you, so legible code is better code.
 
Junilu Lacar
Sheriff
Posts: 11144
160
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
John Pacuta wrote:
Your question was if there was a simpler way. My question is, is there a way that tells a story of what is happening? Time, cost and utility all exist in a balance but I know the character "l" should never be used to represent a variable because of how syntactically weak it is compared to 1 and I. I know it seems very trivial, but the first person debugging your code will probably be you, so legible code is better code.

I like how you think. Please accept a cow from me.

(You actually have no other choice but to take it. However, since you're new around these parts, I don't want you to misinterpret our normal expression of "Have a cow!" -- around here that's a compliment, not an expression pertaining to extreme distress.)
 
Carey Brown
Bartender
Posts: 2993
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's your same code with some of my comments thrown in. Overall you've done a good job. You need to be much more generous with your use of white space.
 
Nigel Browne
Ranch Hand
Posts: 704
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A few comments on your code.
line 30 retValue = f; you haven't declared a variable retValue
line 18 this should actually be your pivot

This eleminates your first swap and increment of f
In your second while loop condition you check that f < l, you already know this is the case as that is the condition for your first while loop. Then in your third while loop you check for less than or equal to, this would be better as the condition to the first while loop.

In your second code block line 2 MIN is never used.

Why did you create a sort method that just calls the qSort method? You know the name array you are passing to qSort in your main method of Q_Sort therefore you could call qSort directly from there.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!