Wednesday, August 1, 2007

Hello World: A New Requirement

I am proud to say that this blog gets hits from all over the world. (Hello Finland, France, Brazil!)

These hits help me with the Big Picture, as does the calendar of Paris on my desk: it is a big world out there. Many people, many cultures, many languages.

Which led me to this thought: it bothers me that "Hello World" is always in English.

I think the venerable first program should always be internationalized, because:

  • It helps keep the Big Picture in mind. I18n is one of the universal issues of computing
  • In addition to showing language syntax, it shows the i18n features. "What do you mean the language doesn't have Unicode support?"
  • In an education environment, it teaches i18n to children from the start while reminding them that there's more than English. It also teaches issues of font, Unicode, etc.
Admittedly, the New Hello World is not minimalist any more and not necessarily pretty. But it would truly be able to say "hello!" to the world.

Here's a version in Groovy. It presumes that there is an i18nized labels.properties file in the current directory.

For example: labels_fr_ca.properties would contain

msg=Salut Monde!

Idea: why not leave "Hello World", in a different language, as a comment? Be sure to specify language, country, and variant codes as appropriate. (This is Java-centric: see here for details)

If you leave a comment, and email me at codetojoy through gmail, I'll send you a sticker!

The Groovy version:
// Requires labels_[Locale].properties
// with definition of key called 'msg'
//
// Locale = the various ways of specifying locale in Java
Locale locale

boolean hasLanguage = ( args.length >= 1 && args[0].length() > 0 )
boolean hasCountry = ( args.length >= 2 && args[1].length() > 0 )
boolean hasVariant = ( args.length >= 3 && args[2].length() > 0 )

if( hasLanguage && hasCountry && hasVariant ) {
locale = new Locale(args[0], args[1], args[2])
} else if ( hasLanguage && hasCountry ) {
locale = new Locale(args[0], args[1])
} else if ( hasLanguage ) {
locale = new Locale(args[0])
} else {
locale = Locale.getDefault()
}

ResourceBundle labels = ResourceBundle.getBundle("labels", locale)

println labels.getString("msg")

5 comments:

Unknown said...

I can't say I agree. The fact that 'Hello World' programs happen to print "Hello World" is not the point. They are designed to be quintessential examples of some technology. Introducing i18n adds a whole bunch of complexity that distracts from the point.

Unless of course your goal is to show the quintessential internationalization example, in which case this makes sense.

Mike Venneman said...

I agree with MEaster that "Hello World" should be internationalized because it should be the "quintessential internationalization example"

I propose that the "quintessential examples of some technology" should be renamed to "Hello English-speaking People" or "Hola Gente de Habla Hispana" etc.

This is, of course, in jest, but I like the idea of keeping i18n in the front of our minds and to introduce it early in all disciplines (not just Computer Science). I would have been better served to have been exposed to this earlier myself.

P.S. “Hello World” displayed to a screen, for instance, does not give consideration to the blind, who are, in fact, part of the world, too.

Anonymous said...

What about a grid-driven Hello World?

Michael Easter said...

re: the point.

Like I said in the post, it is true that the new Hello World is no longer minimalist.

If one is just trying to get something to compile in a brand new environment, then good ol' Hello World makes sense.

But in a book or a presentation, I think that i18n is important enough that it should be part of the demo. The new HW shows not only syntax and the programming environment but also the ease/difficulty of i18n for that language.

e.g. I'm not an expert in Ruby, but Wikipedia states that V 1.x doesn't have native support for Unicode. That "minor" point is illuminated by this.

Most of all though, I just find it "hello world" to be culturally arrogant. IMHO, the addition of i18n is more interesting than changing the text to something like "did this work?".

Ivan said...

"Hello World" in brazilian portuguese: "AlĂ´ mundo" ;)