retard wrote:
I've only seen how Scala solves problems elegantly. These are from some biased blog posts etc. Can you show one example that looks uglier in Scala, but looks decent in D or some other language?

Many languages offer "show" examples that look elegant. A classic example is the one line Haskell quick sort:

qsort (x:xs) = qsort (filter (< x) xs) ++ [x] ++ qsort (filter (>= x) xs)

prominently featured in Haskell's official introduction page:
http://www.haskell.org/haskellwiki/Introduction#Quicksort_in_Haskell

Ain't that cool? But look closer. The advantage of quicksort is that it is an *in-place* sort. The Haskell one creates new arrays for every state in the sort. The other fundamental problem with the Haskell version is that it selects the first array element as the "pivot". This is the worst choice, since arrays to be sorted tend to already be mostly sorted, and quicksort gives quadratic performance to sort an already sorted array with the first element as the pivot.

Ironically, the quicksort example shows a serious weakness of functional programming, not an elegant strength.

Reply via email to