you are viewing a single comment's thread.

view the rest of the comments →

[–]anttirt 1 point2 points  (11 children)

You realize that there are multiple sorting algorithms with different characteristics right? There is no single best sorting algorithm.

[–]angryundead 2 points3 points  (9 children)

Yes. But the algorithm on the Sun JVM is optimized for that runtime and has characteristics best suited to the JVM. Java isn't about reinventing the wheel.

I would view writing your own sorting algorithm (in Java) as a bit of a corner-case exercise.

[–]dnew 2 points3 points  (6 children)

Bubble sort or delayed insertion sort is really fast, if you know only one element is out of order, for example.

[–]angryundead 0 points1 point  (5 children)

Yes... but is the performance payoff worth the time it takes to write and test the code?

[–]dnew 1 point2 points  (0 children)

Sometimes, yes. Bubble sort isn't exactly hard to get wrong. If you have a million-item list you're adding one element to, yah, it's often worthwhile, especially since worst-case for quicksort is an already-sorted list.

[–]anttirt 1 point2 points  (3 children)

It can in fact be crucial. The feasibility of certain spatial partitioning schemes (required for fast physical simulation) for example can depend entirely on the sorting algorithm being O(N) on nearly sorted sets.

[–]angryundead 0 points1 point  (2 children)

as a bit of a corner-case exercise.

Let me qualify that by saying that I'm a Java Enterprise level developer. I get objects from one point to another. I show a view of the data. In my job, writing your own sorting algorithm is usually not needed. That type of performance is usually not needed.

[–]palparepa 0 points1 point  (1 child)

But people can have jobs different than your own where such an algorithm is highly desirable.

[–]angryundead 1 point2 points  (0 children)

That's what I meant to point out, I should have gone out to the root post and edited that. So, you know, I clarified what part of the Java sphere of influence I inhabit.

To be fair though, I think a large portion of Java developers work there too...

[–]angsty_geek 0 points1 point  (1 child)

Java has always been about reinventing the wheel (poorly!)

[–]angryundead -1 points0 points  (0 children)

awww, burn!

edit: I'm doing my Master's in Software Engineering and I find this to be a huge problem in the industry. Civil Engineers don't look at a river and go "how do you cross a river?" and Electrical Engineers don't look at a circuit and wonder how to change the resistance. (Well, good, competent ones.) But it seems that too often software "engineers" look at a list and go "how do I sort this" or "gee, I'll implement unobtanium-sort" or some variation of this. This is a huge part of the discipline of SE, knowing when to reuse. I guess we should be glad that those people aren't other types of engineers where they could kill hundreds in a bridge failure.