Hello World

Hello Worlds are important. They’re particularly important when talking about teaching programming. How much do you need to understand in order to do the absolute simplest thing possible?

package com.writeoncereadmany.sillylittledemos;

public class HelloWorld
    public static void main(String... args)
        System.out.println("hello, world");

That’s Java. It’s a bad hello world. It illustrates clearly what’s wrong with Java as a language for beginners: in order to do anything, anything at all, you’re introduced to packaging, classes, method definitions, words and curly brackets and dots all up ins.

When explaining this code, to beginners, you put that up on screen and then have to say “but ignore all of this, all you care about is this one line”. Straight away, you’re teaching people to dismiss part of the code as magic – sure, you explain it later, but the very first lesson – even before you get to “this is how to do anything” – is “you don’t need to understand all this”.

That’s a really bad introductory lesson. And let’s not even start on actually running that code, once it’s written.

print "hello, world"

That’s Python. It’s a good hello world. There are two parts to it: what you do, and what you do it to. Verb, subject. The only piece of jargon or arcane symbology is the quotes around “hello, world”, and that seems entirely reasonable, as that’s how quotes are used in everyday English too.

As for running it: you don’t even need to save it. Just load up a REPL loop, type in that line, and hit return.

This isn’t to say that Python’s a better language than Java – that’s a much broader question, on which I have Opinions but this isn’t the time for that.

It isn’t, in itself, an argument that Python’s a better teaching language than Java either.

Rather, it’s an illustration of what’s wrong with Java as an introductory language. It boggles my mind that it’s so widespread as a default language (frequently to the total exclusion of all others) in CS courses.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s