Realcodeart.com

Hello, world

The program people teach first. The book page stays off the object.

Brian Kernighan, made famous by the 1978 C book

Get it on a mug or tee →

In 1974 Brian Kernighan wrote an internal memo at Bell Labs called Programming in C: A Tutorial. It begins the way a great many tutorials have begun since: with a program small enough to type in one sitting and large enough to prove that the tools work. The program prints a greeting and stops. The greeting is hello, world. The memo was not a book. It was how a laboratory taught its own language to its own people, C being new enough that the teaching had to be written down before the habit existed.

Dennis Ritchie had designed C as the language the Unix kernel could move into, a step up from the untyped B that Kernighan and Ritchie and their colleagues had been using. The tutorial's job was narrower than the language's job. It had to show a newcomer a function, a string, and a way out of the program. Kernighan chose a greeting rather than a calculation. A greeting is obviously correct when it appears, and obviously wrong when it does not. There is no numerical tolerance to hide inside. The toolchain either produced the line or it did not: editor, compiler, linker, loader, run.

In 1978 Kernighan and Ritchie published The C Programming Language. The first chapter made that same small program the first thing a new C programmer was asked to type. The book traveled. Universities taught from it. Other languages copied the ritual, sometimes as a matter of documented tradition and sometimes because an author had learned C first and could not imagine a manual that began anywhere else. The phrase became the name of the ritual. People who have never seen the memo still know what a hello-world is: the smallest program that speaks.

The bars are that program. A main, a call, a string, a closing brace. They are not a photograph of the 1978 page, and they are not the tutorial's surrounding prose. The book is still in copyright. The page layout, the section heading, the paragraph that tells you to compile: those stay in the book. A lawyer cleared the listing of the bars, which are the program itself, the thing the memo and the book were talking about. The product page says so, in the notice. The book page is not printed on the object. That limit is the difference between a piece marked notice and a piece that would have been a reproduction of a chapter.

It is worth being plain about what clearance does and does not mean. It does not put the book in the public domain. It does not make the K&R text a slogan you can stamp on cloth. It says the bars, as an abstract of the program, may be listed, and that the page beside them must keep the boundary visible. This essay keeps the same boundary. It tells you who wrote the memo, who wrote the book with him, and why the greeting won. It does not reset the type of the chapter.

The program is also a test of a machine's hospitality. If a new computer, a new operating system, or a new compiler cannot run it, nothing larger is worth attempting. Generations of install instructions have used it that way, as a canary. When the canary sings, the environment is alive. The mug is a picture of the canary, not of the mine. Four lines, or however many the bars resolve to once each token has a color, sitting on ceramic because the shortest program in the culture is still the one people recognize.

Kernighan's credit on this site is careful about the year. The piece is dated 1978 because that is when the book made the program famous. The memo is four years older. Both facts belong in the history, and neither fact requires the book page on a shirt. The notice is the third fact: a lawyer cleared the bars, and the book stays off the object. A buyer is purchasing the color of a greeting, with the provenance written where provenance belongs.

The colors do the last bit of teaching. A string is green, a name is the color of names, punctuation is plain. A person who has never written C can still see that the program is mostly one quoted line with a little machinery around it. That proportion is the fame. The machinery is how C says begin and end. The line is the greeting the world kept.

Mug and tee of Hello, world