~ / initial commit / Go

Issue #02 — "hello, world"

Go

The first commit of the Go repository is backdated to 1972 and attributed to Brian Kernighan. It's 'hello, world': the original, in the B language.

languagego
the commit
repo  golang/go
sha  7d7c6a97f8
author  Brian Kernighan
date  1972-07-19
message  "hello, world"
stats  1 file · +7 lines

Git did not exist in 1972. Go did not exist in 1972. The author of the initial commit of golang/go was born before 1972, and he did not use a computer to make it.

And yet, when you run git log --reverse on the Go repository, this is what you see:

commit 7d7c6a97f815e9279d08cfaea7d5efb5e90695a8
Author: Brian Kernighan <research!bwk>
Date:   Tue Jul 19 05:05:45 1972 -0500

    hello, world

1. One file. Seven lines. A time machine.

The commit contains exactly one file: src/pkg/debug/macho/testdata/hello.b. It is seven lines long. It is not written in Go. It is not written in C. It is written in B, the language Ken Thompson designed at Bell Labs in 1969, which became the direct ancestor of C.

Here is the entire file:

main( ) {
	extrn a, b, c;
	putchar(a); putchar(b); putchar(c); putchar('!*n');
}
a 'hell';
b 'o, w';
c 'orld';

If you are squinting: 'hell', 'o, w', and 'orld' are multi-character constants. Each word is packed into a machine word, four characters at a time. putchar then prints them word by word, followed by '!*n', which is B's way of writing the newline escape. When run, the program prints hello, world.

This is the "hello, world": the one from page 7 of Brian Kernighan's 1972 A Tutorial Introduction to the Language B. The document is widely considered the first published instance of the phrase in a programming example. Every "Hello, World!" you have ever written is a descendant of this file.

And somehow, it is the first commit of the Go repository.

2. How did it get there?

It is not a prank. It is not an accident. It is test data.

The file lives at src/pkg/debug/macho/testdata/hello.b. It is a fixture for Go's Mach-O binary parser: the package that lets Go read compiled binaries on macOS. Someone needed a tiny, old, compilable program to produce test binaries, and rather than write a new "hello world" for the umpteenth time, they reached back to the source and used the original.

But here is the thing. When the Go authors imported their code into git, they did not just import the files. They imported the metadata. Whoever set up the repository told git that hello.b was authored by Brian Kernighan, in 1972, at Bell Labs (research!bwk is a UUCP bang-path email address, the addressing format of the pre-DNS internet). The commit is a deliberate, load-bearing easter egg, engineered so that git log --reverse on the Go repository begins with the birth of "hello, world."

3. The second commit

git log --reverse on golang/go gives you Kernighan's 1972 program. Only when you skip to the second commit do you leave the time machine; and when you do, you land in 1974, for a second Kernighan file. And 1988. And 1989. The first several hundred commits of Go are not Go at all. They are the history of programming languages, committed in chronological order, with the real Go source code waiting patiently behind them.

The actual first commit of actual Go code (the one written by Go's actual authors, doing actual Go work) comes much later in the log. It is buried under decades of prehistory that the Go team quietly placed in front of it.

4. Why I love this

Most initial commits are a developer trying to get out of the way of their own tool. git init, git add ., git commit -m "initial commit", get to work. The Go team did the opposite. They looked at git log --reverse (a command almost nobody ever runs) and decided that, on the off chance someone did, they should find something beautiful there.

It is a gift for the curious. It costs nothing. It changes nothing. It is the kind of detail that rewards the person who bothers to look, and punishes no one for not looking.

There is a thesis somewhere in here about how the best software gets made: by people who spend time on things that almost nobody will ever notice, because they know that the people who do notice are the people worth making the software for.

Or maybe it is just a very funny joke. Seven lines. Fifty-two years. One commit.

5. Footnotes from the commit log

  • The Go repository contains hello.b not just because it is charming, but because it parses to a valid Mach-O binary when compiled with the right toolchain. It is simultaneously a historical artifact and a unit test fixture.
  • Kernighan's 1972 tutorial is the only place "hello, world" appears before it appears everywhere. Before that, introductory programs tended to print "HI" or compute Fibonacci numbers. "Hello, world" had to be invented, and Brian Kernighan invented it.
  • The research! prefix in the commit email is a UUCP bang path: the store-and-forward email routing scheme used before @ hostnames were standardized. "research" was the name of the computer at Bell Labs research.
  • Go was publicly announced in November 2009. The golang/go repository was opened in late 2014 when Go migrated from Mercurial. The prehistory commits were layered in during that migration.