Live data from Hacker News

Quicksort is the new Hello World

blog.rmontanaro.com

1–10 of 64 posts

Re: Quicksort is the new Hello World

#2
I think your point is valid and of course interesting for programmers, but KR's "Hello, world!" is still relevant for students and novices. Maybe reading/writing on a file would be more useful nowadays, since it does not demand knowledge of algorithms.

Re: Quicksort is the new Hello World

#3
For a veteran programmer learning a new language like Haskell, I agree completely.

For a novice programmer learning their first language, they probably don't understand the quicksort algo and probably have no concept of arrays or any data structure. Visually displaying "Hello World" is very simple and teaches you two basic parts of a language: - Syntax - Printing stuff

On another note, someone learning HTML for the first time will have no reason to do quicksort.

Re: Quicksort is the new Hello World

#4
post #2

I think your point is valid and of course interesting for programmers, but KR's "Hello, world!" is still relevant for students and novices. Maybe reading/writing on a file would be more useful nowadays, since it does not demand knowledge of algorithms.

A large part of the value of a hello world is to check that you've actually installed the language correctly and can compile/run code. Printing hello world is just the simplest way of proving it.

Re: Quicksort is the new Hello World

#5
I don't think "Hello World" will ever cease to be useful for the simple task of making sure everything's installed and operating correctly. Quicksort is certainly beautifully concise in Haskell, but it's not in all languages, and I want a low probability of errors when I'm just getting things up and running for the first time.

Re: Quicksort is the new Hello World

#6
Although this version is very simple, concatenating and creating lists at runtime ruins performance (and it takes extra memory). Please make it a good example by doing a version of Quicksort with in-place partition.

Re: Quicksort is the new Hello World

#7
Hello world is valid for checking that you have everything installed properly and it's the fastest way to make sure you get the most basic syntax of the program.

It's not like the first thing you're going to do is write out all of quicksort to see if it's easy. You're going to fiddle with numbers an arrays a bit first, particularly if your language has some kind of interactive console. In fact, I wouldn't be surprised if the first thing you do in the language is actually 1+2.

There's quite a bit of syntax you need to learn before quicksort becomes a relevant test.

If you're looking for a good language to build a quick website backend in you probably don't even care about that, you'll care more about having nice ways of passing information around and checking that it has a decent inbuilt sort method.

Re: Quicksort is the new Hello World

#8
I think something simpler would be a better Hello World equivalent. The first program I generally write in any functional language (usually as a sanity check) is one to calculate the factorial of a number.

Re: Quicksort is the new Hello World

#9

    qsort :: Ord a => [a] -> [a]
    qsort []     = []
    qsort (p:xs) = qsort lesser ++ [p] ++ qsort greater
        where
                lesser = filter (= p) xs
I know nothing about Haskell but I don't think this code implements the original quicksort algorithm which sorts the input in-place. Moreover the two-pass of filter over the list and the concatenations cause unnecessary overhead. Thus, even if the sample code is simple and elegant, a real-world implementation would surely be a bit longer than the given example.

Re: Quicksort is the new Hello World

#10
tl; dr, but a quick note: the presented algorithm takes the first element as the pivot element p:

   qsort (p:xs) = ...
This is not recommended as it results in worst-case behavior on sorted input lists. (Another commentor correctly pointed out that it requires extra memory for the intermediate lists, too.)
Post reply on HN