Foreshadowings of the Go programming langauge
2019-12-20
My main programming language these days is Go. I like reading reading old papers and books. When reading things coming out of the old Bell Labs, I often see glimpses of ideas that made it into Go.
This is not an exhaustive list. There are many other places where you can see the Plan 9 - Go connection.
Rob Pike: Notes on Programming in C
Notes on Programming in C is a paper from 1989. Rob Pike is one of the three original designers of Go, along with Robert Griesemer and Ken Thompson.
Function pointers
According to Pike function pointers are good. He talks about a programming style where you create a kind of "protocol" where you can swap in different sets of function pointers that satisfy that protocol.
There is this idea of a protocol, in that all functions used similarly must behave similarly.
I argue that clear use of function pointers is the heart of object-oriented programming. [...] The O-O languages give you more of course - prettier syntax, derived types and so on - but conceptually they provide little extra.
This strikes me as the same idea as Go interfaces. Both the idea of having them, and of leaving out other parts of "Object Oriented".
Ken Thompson: A New C Compiler
A New C Compiler appears to be from around 1990.
If you're going to reinvent Unix by creating Plan 9, you might as well reinvent C. That is an exaggeration but more or less the point of the article.
I don't understand everything he is talking about but it's fun to read what the original author of C would have done differently. Some things I believe made it into later versions of the C standard, such as sparse initialization of arrays.
Of note for Go is the appearance of anonymous struct embedding. Things in structs usually have names but in Go, you can embed structs anonymously, and then access embedded fields transparently through the outer struct.
type Foo struct {
Bar string
sync.Mutex
}
f := &Foo{}
f.Lock() // Transparently uses Foo.Mutex.Lock()
This paper from Ken Thompson shows the same idea, implemented in the Plan 9 dialect of C described by the paper.