3 ms·
Not that I typically defend Java, but I think that (going by your Rosetta Code algorithm comparison test) Java fairs well against a few mainstream languages: R
by Crito 12y ago
Not that I typically defend Java, but I think that (going by your Rosetta Code algorithm comparison test) Java fairs well against a few mainstream languages:
Rosetta Code's Java Quicksort: http://rosettacode.org/wiki/Sorting_algorithms/Quicksort#Java http://rosettacode.org/wiki/Sorting_algorithms/Quicksort#Jav...
Not great, that first line is a wreck in particular, but not terrible either.
Compare that to this though: http://rosettacode.org/wiki/Sorting_algorithms/Quicksort#C.2B.2B http://rosettacode.org/wiki/Sorting_algorithms/Quicksort#C.2...
Really quite ugly looking code.
Now, this isn't entirely fair; one of C++'s faults/benefits is that depending on your shop and/or framework/libraries, "idiomatic" C++ can vary greatly. Template heavy C++ tends to look like vomit. C++ that uses Boost will typically be more unpleasant to look at than C++ that uses Qt (imho anyway).
Java really comes into it's own horrible self when you get beyond mere algorithm implementation. A quicksort method in Java will tend to be relatively fine, but for projects larger than that it becomes idiomatic to make your java code a real mess.
- cheepin 12y agoQuicksort looks significantly better in a functional style. Here's some Haskell, but it certainly doesn't use any Haskell-exclusive features: quicksort :: Ord a => [a] -> [a] quicksort [] = [] quicksort (p:xs) = (quicksort lesser) ++ [p] ++ (quicksort greater) where lesser = filter (< p) xs greater = filter (>= p) xs
- Crito 12y agoDefinitely. Pointing to C++ as a mainstream language that is uglier than Java seems a bit like missing the point since it is basically the exception that proves the rule, but he did say "in any other mainstream language. Period." ;)
- loqi 12y agoWhen is quicksort not quicksort? When it's not in-place: http://augustss.blogspot.com/2007/08/quicksort-in-haskell-quicksort-is.html http://augustss.blogspot.com/2007/08/quicksort-in-haskell-qu... I love me some Haskell, but this particular example is kind of a bait-and-switch.