Monday, July 21, 2008

hello, world

Brian W. Kernighan and Dennis M. Ritchie introduced their C programming language to the world in a 1978 book obliquely titled The C Programming Language. They opened with a 3-line program that simply prints "hello, world" on the screen. (Remember, these are the days of terminals and command line programs, and the screen was what was endearingly called stdout.)

In an earlier post, I waxed nostalgic for the software development world of 30 years ago, so I thought it would be entertaining (for me, at least) to consider what it would have been like to be the maintainer of this program over the past three decades.

1980's:

First, the greeting itself would have to translatable into different languages, so the program would probably be modified to read the greeting string from a file on disk. That way, translators could localize the string for different places without having to modify the code.

Since the location of the string file would probably vary from one installation to another, we'd need some way to identify the file with its site-specific path. This could be done with an environment variable or a resource file on a *n*x system, or a .ini file on Windows. (The registry was still years away). On the Mac, perhaps it would be stored in the resource fork. A more general approach would be to put the string in a database, so it's value could be retrieved via a query. This could be implemented in the then new SEQUEL (later SQL) query language.

Now, of course, a string with 8-bit characters can only represent some Western European languages, so we'd have to enable the program to support 16-bit characters, and make the corresponding changes to the resource files and/or database. Since it's inefficient to use 16-bit characters all the time, the program would have to test the language to determine whether to use 8-bit or 16-bit representations. We also need fonts which can display the necessary characters in all the languages we'll be using.

Also, since we now have workstations and personal computers with graphical user interfaces, we'd want to display the greeting in a window, instead of just on a terminal screen. In fact, Charles Petzold did include a sample "Hello, Windows" program in his book, Programming Windows. It was about 60 lines of code.

1990's:

So by now, it's time to convert the code to C++. This will, of course, make it easier to maintain, and it's just generally cooler. For the C++ implementation, we'll want to have classes for the display window and for the string, to hide all the ugly implementation details of multiple string formats, and of differing window systems.

We should probably also make it client/server based, so we can ... uh, ... well, just 'cause that's the way to go. We'll have a "hello, world" server, hwserv, which will keep track of who needs to be greeted, and will display the appropriate greeting. The server can keep the database of greeting strings, and query each client for the appropriate language to use.

But now, of course, there's that World Wide Web thing to consider. Some clients will just be using various Web browsers, and we'll have to use Perl CGI scripts to create dynamic HTML pages containing the suitable greeting.

Of course, we also want to use relevant meta-tags, so that search engines can find our page. We'll probably also consider commercializing the page (Surprisingly, displaying "hello, world" doesn't bring in a lot of money!) by including ads. And we'll need counters and statistics to know how many people are actually seeing our greeting.

Now that we think about it, the Perl CGI scripts are pretty slow. We'd be better off using downloaded Java applets, or possibly JavaScript, to determine the local language and select the greeting string. Unfortunately, just downloading Java applets is slow, and JavaScript doesn't work the same way from one Web browser to another.

We also need to implement security so only those who are entitled to be greeted can receive our greeting page, and so that the site itself is not subject to hacker and denial-of-service attacks.

2000's:

Downloading all the possible greeting strings in all languages is really unnecessary. It would be more efficient to determine the language and then fetch a short XML representation of the appropriate string, using AJAX.

Since our greeting must be state-of-the-art, we're going to create an animated sequence to display the "hello, world" graphic via Flash. We can use ActionScript to animate the text, which will be generated on-the-fly in the appropriate language.

But wait! This needs to run on a cell phone! Of course, it will have to display correctly, regardless of the size and orientation of the screen.

And it needs to be position-sensitive, via the built-in GPS chip, so that you automatically get the appropriate greeting string for the current location of the phone.

And there must be an audio version, so it's accessible to the vision impaired ...

And it should be touch-aware ...

And it should work over WiFi or 3G networking ...

And ...

And ...

And ...

hello, world

No comments: