hello, world

Personally, by reading “hello, world”, I evoke orange and warm afternoons, with my eyes strained (and soothed) by code. Nice, and overly inefficient Pascal code. In some images, a few BASIC snippets interleave, but those are not that nice to remember…

In calm thoughts, these two words (with the comma) bring to mind plenty of images. More often that not, I hold “hello, world” in fond remembrances. For this post I’ve slightly modified the default WordPress post title, in favor of the original Kernighan‘s form: no capitalization and presence of comma. Through the years, it seems to me that this sequence lightens my worries when coping with new languages, systems, things. Somehow, the mind has understood that once “hello, world” is done, then reaching the entire system is achievable. Kind of Pavlovian Conditioning, I guess.

In K&R’s C Tutorial, this feel at ease perception it’s also intended:

The only way to learn a new programming language is by writing programs in it. The first program to write is the same for all languages: Print the words hello, world. This is the basic hurdle; to leap over it you have to be able to create the program text somewhere, compile it successfully, load it, run it, and find out where your output went.

This way, “hello, world” should be our first step for pummeling through the new beast (language).

Origins and B detour

In respect to its origins, the Tutorial Introduction to the Language B, by Kernighan, contains the primigenial use of our salutation, under the section “External Variables”:

main( ) {
extrn a, b, c;
putchar(a); putchar(b); putchar(c); putchar('!*n');

a 'hell';
b 'o, w';
c 'orld';

I recognize a lot of familiar things going on here in B:

  1. First, our beloved main is already incarnated.
  2. Parentheses, brackets, semicolons and the syntax for passing arguments are right in their position.
  3. And extrn -> extern.
  4. Clearly, that '*n' resembles '\n': notice that the literal passed to putchar is '!*n' (comprised of two characters) and thereby the exact, original output is “hello, world!”, with the “!”.
  5. Interestingly, B is typeless and not suited for numeric computation, so no int, no float.
  6. Besides, a, b and c are global variables (static storage), which means they can be initialized. But for any B function being able to access such global variables, use of extrn declaration is mandatory… delightful. Now, albeit the language does not include a mechanism for explicit types, the three variables in the example are initialized to character constants, which in B are single-quoted and can have from one to four ascii characters (in C a character constant is formed by enclosing a single character from the representable character set within single quotation marks). By the way, the upper bound of four characters is a hardware restriction, as Stephen Johnson points out in the Users’ Reference to B on MH-TSS:

A character constant is represented by ' followed by one or more characters (possibly escaped) followed by another '. It has an rvalue equal to the value of the characters packed and right adjusted, with zero fill. Obviously, the number of characters in a character constant is a machine dependent quantity; on the H6070, up to four characters are allowed.

B looks a lot like C, and had its roots in an older language called BCPL. One of its authors, Ken Thompson, when asked if B was a subset of BCPL, answered this:

It wasn’t a subset. It was almost exactly the same. It was a interpreter instead of a compiler. It had two passes. One went into intermediate language and which one was the interpreter of the intermediate language. Dennis wrote a compiler for B, that worked out of the intermediate language. It was very portable and in less than a day you could get very versatile (not clear). Typically the interpreter was a set macros for your interpreter, they were very field orientated and you just define these macros with these fields and then write a little interpreter that would switch the set routines, and you had to write about twenty three-line routines, and it would run. And it was very small, very clean. It was the same language as BCPL, it looked completely different, syntactically it was, you know, a redo. The semantics was exactly the same as BCPL. And in fact the syntax of it was, if you looked at, you didn’t look too close, you would say it was C. Because in fact it was C, without types. There’s no word like interchar or struct or anything like that. The word for… There was a word for extern, which means to declare an external thing. There was a word auto, which declared an auto thing.

“Dennis” of course is the other author (and C’s creator), Dennis Ritchie. Chapter 1 of The C Programming Language by Kernighan and Ritchie, includes the clearer version:

   printf("hello, world\n");

Now the compiler does more things for you. Good.


Personally, by reading “hello, world”, I evoke orange and warm afternoons, with my eyes strained (and soothed) by code. Nice, and overly inefficient Pascal code. In some images, a few BASIC snippets interleave, but those are not that nice to remember 🙂 That was not too long ago. I had to complete projects and projects in Pascal for some undergraduate courses, which amounted to lots of tangled pasta. Lovely functions and procedures which required scrolling several pages in order to reach the closing end. Today, I wonder how I was able to bear all that insanely long units. Miracles of youth. I do remember having one of this procedures for drawing a primitive text-mode GUI, based on ALT +196 and ALT + 179: Write('─') and Write('│'). Thanks Turbo Pascal, for so much blessings. Such procedure was flooded with this:

{ Draw a line }
For Loop := 1 To 80 Do

You’ve gotta love the obnoxious formatting (including the capitalization of To and Do), the dumb comment, the shining constants, and the good programming practice that such For-flooded procedures are. And for clarity, I omitted that such For was inside a super-nested If. Beautiful. Undoubtedly, spaghetti code was my premature approach to cryptography. That code, by the way, reminds me of the First year in college style (“hello, world” GNU joke).

I used to think that Pascal was a cool language (I still do). But other work by Kernighan, again and perhaps unwillingly, made explicit to me that the distance between boys and men was greater than I had thought. Dated April 2, 1981, Why Pascal is Not My Favorite Programming Language shed new light on my lag. From there on, Pascal lost some charm, and some of my spare time. But I would not say it’s not my favorite language… I’d prefer to say that it’s one of my favorite languages, with C being the most liked (so far). The inconsistencies of affection…

A little homage to a great buddy. “hello, world”.

6 thoughts on “hello, world”

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.