249 points · by breck · 2y ago · 130 comments
* He joined Princeton’s CS department in 2000 but taught at least one class there as early as 1993 while still at Bell Labs Research (on sabbatical?)
* One of his students regularly brought a 386sx laptop (running pre-1.0 Linux) to class and when Brian was asked more obscure questions about what awk did which he couldn’t remember, the student would run commands in awk and feed Brian the definitive implementation answer. So Brian had some exposure to Linux moderately early on.
* Here’s a writeup from him on putting AT&T’s toll free phone directory on the internet back in fall 1994: https://www.cs.princeton.edu/~bwk/800.html
nawk (One True Awk / AT&T awk / BWK awk): the original awk, still maintained; is used by macOS, FreeBSD, OpenBSD, and NetBSD https://github.com/onetrueawk/awk
mawk (Mike's awk): the default awk on Debian https://invisible-island.net/mawk/
gawk (GNU awk): the default awk in lots of other places https://www.gnu.org/software/gawk/
I believe both were available in Linux back then. I believe in the above anecdote both were consulted with the emphasis on AT&T-style awk for obvious reasons.
Smells like the post author, no?
Sometimes, I feel extremely privileged to be living today. It's like a mathematician being able to interview Euler or a physicist interviewing Newton.
I didn't like his talks earlier (had only seen parts of a few), don't know why.
but interestingly (to me), this one seems to be good, at least at the start, where I am now.
as the real talk starts after the ads, looking at him, for some reason, I thought he looked like a sinister mafia don wearing a tie. :)
His attitude seems to be that he will interview anyone without pre-judgement, and try to find common ground with them or something. "Woke" people like myself view that as enabling bad actors.
I have listened to some great interviews from him, so it is a mixed bag.
Like you, I found Lex off-putting in that he will platform anyone, and then will just say Love will prevail, I think its incredibly naive.
If you like podcasts of a very intelligent person interviewing very accomplished guest thinkers, Sean Carroll's Mindcast is slightly higher level: https://www.preposterousuniverse.com/podcast/ (tho I don't think Donald Knuth has been on that one, lots of other computer folks have).
So just normal JRE content
https://en.wikipedia.org/wiki/Brian_Kernighan
http://www.linuxjournal.com/article/7035
http://www-2.cs.cmu.edu/~mihaib/kernighan-interview/index.ht...
https://web.archive.org/web/20090428163341/https://www.princ...
https://web.archive.org/web/20131126220450/http://princetons...
the 7th edition unix version of awk from 01979 https://www.tuhs.org/cgi-bin/utree.pl?file=V7/usr/src/cmd/aw... (from https://www.tuhs.org/Archive/Distributions/Research/Henry_Sp...) is only 2680 lines of source code, which is pretty astonishing. the executable is 46k and ran in the pdp-11's 64k address space. as far as i can tell, that version of awk, and also the one documnted four years later in tupe, didn't even have user-defined functions. neither did the v7 version of the bourne shell, i think
bc, however, did
Also known as “old awk” or (retronymically) “oawk”. Heirloom still carries[1] what should be a descendant of it (alongside the more familliar nawk).
Also,
> the executable is 46k
thus still a bit larger than Turbo Pascal 3.02[2] :) That didn’t have a regex engine, admittedly.
i haven't compiled version 7 myself so i don't have a clear idea of how big it is
a slight correction to my above comment! on running `file *` in bin/, i see, among other things
at: PDP-11 pure executable
awk: PDP-11 separate I&D executable
bas: PDP-11 pure executable
basename: PDP-11 pure executable
bc: PDP-11 pure executable
if i understand correctly, this means that this awk executable is built with what we used to call the 'small memory model' on the 8088, using separate instruction and data segments. that way, awk could have data stored at the same address as executable code, so you had 64 kibibytes available for just the data. you didn't have to squinch your awk program and all its data into the 65-46 = 19 kilobytes left over after the awk executable was loadedthis, in effect, allows you 128 kilobytes for the functionality of your program: when you call an awk builtin function (usr/src/cmd/awk/proc.c lists seven named functions: substr, sindex, sprintf, printf, print, split, and instat) you're invoking code in the instruction segment, while the logic of your interpreted code shares the data segment with the data you're manipulating (strings or arrays or whatever)
so it's at least misleading that i said it 'ran in the pdp-11's 64k address space'
not all pdp-11s supported separate instruction and data segments (i think the more expensive pdp-11/45 did, but the pdp-11/40 and pdp-11/20 didn't) and most of the 7th edition executables didn't require that. but awk, adb, dcheck, dd, fgrep, icheck, lex, ncheck, refer, restor, sort, tar, tbl, uucp, uulog, uux, and yacc did. i'm not sure how you were supposed to run a unix system without dd, icheck, tar, uucp, restor, or adb (sdb and dbx didn't exist), so i think maybe at this point they had given up on supporting the smaller models
awk is more than that: having introduced the "function" keyword, for e in a, semicolon-less syntax, stringly-typing, delete x[e], etc, etc, it's quite obviously the base for JavaScript, and Brendan Eich said as much [1].
[1]: https://brendaneich.com/2010/07/a-brief-history-of-javascrip...
semicolonless syntax is in js, tcl, lua, and sh, but not awk or perl; in awk omitted semicolons are interpreted as string concatenation
> 01979
thats not how you write years, or even numbers really.
That book, along with The Practice of Programming by Kernighan/Pike and Byte magazine etc were my "Stack Overflow" for the 1980s.
Second, while the programming world fancies itself a very fast mover, it really isn't, and it especially wasn't back then. 20 years isn't necessarily as long as you would think in 2024. We're still trying to convince people in 2024 that you really don't need a language that will happily index outside of arrays, and how long has that been a staple in existing languages? (You may think that's silly, but we've had that fight on HN, yes, yea verily, this very year. Granted, this is winding down, but it's still a live argument.)
There's a lot of things that showed up in some language in the 1960s or 1970s and wasn't widely adopted for another few decades.
(Though I suspect one problem with Lisp is that back in the day, its performance was pretty awful relative to the other things of the day. It was not always the best advertisement for its features. A bit too ahead of its time sometimes.)
That's a little surprising, considering that the classic first book about C, K&R was first published in 1978 and again in 1988, the first and second edition, respectively.
One of the editions, maybe the first, had a simple hash table implementation, that just summed up the ASCII values of the characters in the given string, modulo some value, and used that as the key for the string being hashed.
.
My first real use of hashes was in perl4; with perl5 released in 1996 (https://dev.perl.org/perl5/news/), surely it meant people were also well aware of the usefulness of hash arrays even back then.
— kernighan definitely did not think hash tables were 'a bit exotic' in 01978 —
hash tables (or sometimes other associative retrieval structures) were standard fare in computer science degree programs and were a standard feature of compilers, assemblers, and linkers, of which kernighan had written several at that point; associative retrieval structures are also fundamental to databases and filesystems. in 01979, 7th edition unix (in which kernighan published awk) barely had date formatting but included an on-disk hash table library called 'dbm'
hash tables are the exclusive topic of pp. 506–549 of knuth's taocp volume 3, a standard textbook which came out in 01973. after recommending you some hash functions, on p. 512 (525/739) knuth recommends you check out a survey of hash functions published in cacm by lum, yuen, and dodd in 01971, and he cites papers on hashing in cacm as early as 01959 and in an ibm journal as early as 01957. in the 'history' section (pp. 540–542 (553–555/739)) he traces it back to an internal ibm report by luhn in 01953, and its first report in the open literature to a paper by dumey in 01956. most of the rest of the 739-page book is about how to implement associative arrays of various kinds, although some parts instead concern the string search problem, and the first half is about sorting, and a sorted table can be used for purposes other than associative retrieval
knuth also mentions a 'very influential survey' of hashing published in cacm in 01968 by robert morris, kernighan's coworker at bell labs, and one of the very first users of unix and a major contributor to it
there are several papers about hashing every year in cacm throughout the 01970s, as well as alternative associative-array structures such as tries, sorted arrays and binary search trees. in march 01975 we have https://cacm.acm.org/research/the-algorithm-sequential-acces..., in april 01975 we have https://cacm.acm.org/research/the-quadratic-hash-method-when..., in may 01975 we have https://cacm.acm.org/research/analysis-and-performance-of-in..., in july 01975 we have https://cacm.acm.org/research/a-note-on-hash-linking/, in september 01975 we have https://cacm.acm.org/research/multidimensional-binary-search..., in october 01975 we have https://cacm.acm.org/research/optimizing-the-performance-of-... and https://cacm.acm.org/research/merging-with-parallel-processo..., in january 01976 we have https://cacm.acm.org/research/performance-of-height-balanced..., in february 01976 we have https://cacm.acm.org/research/on-self-organizing-sequential-... and https://cacm.acm.org/research/a-stochastic-evaluation-model-..., in june 01976 we have https://cacm.acm.org/research/a-practitioners-guide-to-addre... (which is about hashing despite the name), in july 01976 we have https://cacm.acm.org/research/compressed-tries/, and in august 01976 we have https://cacm.acm.org/research/an-insertion-technique-for-one.... you could not read cacm in the 01960s and 01970s without frequently coming across hashing, as well as other associative-array structures.
but perhaps kernighan hadn't read cacm? on the contrary, he and his colleagues regularly published in it; he published in cacm once in 01972, once in 01973, and once in 01975, and his colleagues such as stephen johnson, mike lesk, al aho (his coauthor on awk), and, as i said above, robert morris, published there regularly as well
in the practice of programming, kernighan and pike claim that almost all of the time, the only data structures you need are arrays, linked lists, trees, and hash tables (though they wrote this in 01999)
what kernighan is talking about here is including them as a basic language construct, a design choice his 01978 tech report on awk likens to that of snobol4, which was a well-known language but not a mainstream one. in the context of the above cacm articles, you can perhaps see that the daring choice was to offer a single 'good enough' hash table implementation rather than one optimized for a given purpose—and to use it even in place of conventional arrays
— kernighan was not isolated like you were —
kernighan was at bell labs, which was probably the most connected place in the software world at the time
when awk was released in 01979 the internet was already ten years old, and at&t (the parent company of bell labs) had installed all its long-distance links
in 01976 they'd also developed their own 'internet' called uucp, which at the time of awk's release was interconnecting 80 different unix sites, interchanging software updates on a daily basis, over 300-baud and 1200-baud modems. they were also in contact with ken thompson's alma mater berkeley; thompson took a sabbatical year to teach there in 01975. berkeley got a darpa contract to add tcp/ip support to the bell labs operating system 'unix', which would become the majority of the internet during the 01980s; berkeley participated actively in the uucp network
bell labs was also working on the so-called 'advanced communication system', its own misconceived version of the internet, where data would be routed using phone numbers, because data communications had become the fastest-growing source of call traffic. (colin berkshire has written a fantastic overview of this forgotten history.)
The computer world of the time was not clones of Kernighan a thousand times over, nor was everyone reading every single paper any more than people do today. You can't prove the normal world of computing was all aware of all these things by pointing at the very pinnacle of it. I'm talking about the real world, not the best of the best of the best.
Regarding the second point, when I hear the term "associative arrays" or "associative lists" I think of them in a pretty high level of abstraction. Like really: a C struct is an association abstraction. A simple array of structs is not often considered an "associative array", but it can easily be used for the same things.
Maybe it would be more accurate to say that the way they were using associative arrays way newish, rather than the construct itself.
"Associative arrays were inspired by SNOBOL4 tables, although they are not as general. Awk was born on a slow machine with a small memory, and the properties of arrays were a result of that environment. Restricting subscripts to be strings is one manifestation, as is the restriction to a single dimension (even with syntactic sugar). A more general implementation would allow multi-dimensional arrays, or at least allow arrays to be array elements."
Stable release - SNOBOL4 / 1967
you can of course build an associative array in any language, especially if you're satisfied with the linear search used by lisp alists. you can hack one together in a few minutes almost without thinking:
.intel_syntax noprefix
lookup: push rbx
push rbp
mov rbx, rdi # pointer to alist node pointer
mov rbp, rsi # key
2: mov rdi, [rbx] # load pointer to alist node
test rdi, rdi # is it null?
jnz 3f # if not null, skip not-found case
mov rax, rbx # pointer to null pointer is return value
xor rdx, rdx # but associated value is null (sets zero flag)
jmp 4f # jump to shared epilogue
3: mov rdi, [rdi] # load pointer from key field of alist node
mov rsi, rbp # reload key from callee-saved register
call comkey # sets zero flag if rsi and rdi are equal keys
jne 1f # skip following return-value case code if !=
mov rax, rbx # pointer to node pointer is return value
mov rdx, [rbx] # also let’s follow that pointer to the node
mov rdx, [rdx + 16] # and return its value field too in rdx
test rax, rax # clear zero flag (valid pointer is not null)
4: pop rbp
pop rbx
ret
1: mov rbx, [rbx] # load pointer to alist node again
add rbx, 8 # load pointer to next-node pointer field
jmp 2b
(untested, let me know if you find bugs)but that's very different from having them built in as a language feature, like snobol4, mumps, awk, perl, python, tcl, lua, and js do. the built-in language feature lisp had for structuring data 20 years earlier was cons, car, and cdr, which is not at all the same thing
other programs on unix that contained associative arrays prior to awk included the linker (for symbols), the c compiler, the assembler, the kernel (in the form of directories in the filesystem), and the shell, for shell variables. none of these had associative arrays as a programming language feature, though. the bourne shell came closest in that you could concatenate variable names and say things like
eval myarray_$key=$val
here's the implementation of binary tree traversal for setting shell variables in the v7 bourne shell from 01979 NAMPTR lookup(nam)
REG STRING nam;
{
REG NAMPTR nscan=namep;
REG NAMPTR *prev;
INT LR;
IF !chkid(nam)
THEN failed(nam,notid);
FI
WHILE nscan
DO IF (LR=cf(nam,nscan->namid))==0
THEN return(nscan);
ELIF LR<0
THEN prev = &(nscan->namlft);
ELSE prev = &(nscan->namrgt);
FI
nscan = *prev;
OD
/* add name node */
nscan=alloc(sizeof *nscan);
nscan->namlft=nscan->namrgt=NIL;
nscan->namid=make(nam);
nscan->namval=0; nscan->namflg=N_DEFAULT; nscan->namenv=0;
return(*prev = nscan);
}
if you're not sure, that's c (now you know where the ioccc came from)https://www.tuhs.org/cgi-bin/utree.pl?file=V7/usr/src/cmd/sh...
With this, we can correctly implement lexical closures: we simply take the current environment (head of the alist) ssociate it with the lambda body and arguments, and we are done.
______
† 'persistent' unfortunately also means 'stored in nonvolatile memory', so i feel the need to disambiguate
awk-descended languages include perl, tcl, js, python and lua
it's a close race but if i had to pick i'd say the second group is more influential