6 ms·
i've been reading the unix programming environment from 01983 this week (the old testament of kernighan and pike), about 35 years later than i really should hav
by kragen 2y ago
i've been reading the unix programming environment from 01983 this week (the old testament of kernighan and pike), about 35 years later than i really should have. awk is really one of the stars of the book, the closest thing in it to currently popular languages like js, lua, python, perl, or tcl. (what awk calls 'associative arrays' js just calls 'objects'.)
the 7th edition unix version of awk from 01979 https://www.tuhs.org/cgi-bin/utree.pl?file=V7/usr/src/cmd/awk https://www.tuhs.org/cgi-bin/utree.pl?file=V7/usr/src/cmd/aw... (from https://www.tuhs.org/Archive/Distributions/Research/Henry_Spencer_v7/v7.tar.gz 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
- deleted 2y ago[deleted]
- mananaysiempre 2y ago> that version of awk [...] didn't even have user-defined functions 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. [1] https://heirloom.sourceforge.net/man/awk.1.html https://heirloom.sourceforge.net/man/awk.1.html [2] https://prog21.dadgum.com/116.html https://prog21.dadgum.com/116.html
- coliveira 2y agoTurbo Pascal was written in asm and highly optimized to reduce its size.
- fuzztester 2y agoin under 40 KB it had a lightning fast compiler that generated .COM files, and a text based IDE with a WordStar compatible code editor.
- kragen 2y agothe 39.7-kilobyte turbo pascal executable doesn't include the (modest) pascal runtime library, because it is itself written in assembly, not in pascal. awk, being an interpreter, does have to include the runtime library in the same executable as the parser. awk is also written in c rather than assembly, and moreover using lex and yacc; lex compiles the lexer into a deterministic automaton written in c for speed, and all of this is compiled with pcc, whose optimizations were relatively weak by today's standards 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 loaded this, 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
- tannhaeuser 2y ago> the closest thing [...] to currently popular languages like js 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-javascript/ https://brendaneich.com/2010/07/a-brief-history-of-javascrip...
- kragen 2y agoi'd say perl is closer, but for (e in a) is from awk and not perl semicolonless syntax is in js, tcl, lua, and sh, but not awk or perl; in awk omitted semicolons are interpreted as string concatenation
- deleted 2y ago[deleted]
- dakiol 2y agoI read the same book and got the exact same conclusion. Then I read The UNIX—Haters Handbook and thought that Unix tools (like awk) are sadly not good enough anymore.
- kragen 2y agoyeah, there are a lot of questionable design decisions in there that are only defensible in the context of the pdp-11's 64k address space and slow cpu
- fuzztester 2y agowhat are some of those?
- kragen 2y agomaking everything a string, for example. representing string length with null termination. splitting shell variables into words after variable substitution (rather than having a list type). a zillion shell-script bugs when filenames, directory names, search strings, etc., contain spaces. not having user-defined subroutines in sh or awk. no command-line editing. command names and options that read the same as you type them (thus forcing you to choose between unreadable commands and commands that are too unwieldy to type comfortably). no tab completion. more generally, no interactive feedback on what is going to happen when you submit your command. no job control. having to retype command output as new input all the time. table layout that only works with fixed-width fonts. filenames limited to 14 characters. no text search through previous output. hardlinks rather than reflinks. an inflexible security policy defined in the kernel. the reification of . and .. in the filesystem. exposing the layout of filesystem directories to every program that enumerated directory entries. no way to undo rm or mv. no screen editors. arbitrary line-length limits all over the place. . in the path. textual macro expansion as the primary form of higher-order programming. backslashed backquotes. backslashed backslashes. total precedence orderings on infix operators. slightly different regular expression syntaxes for each program. self-perpetuating at jobs. etc. a lot of these have been fixed, but some are hard to fix
- 38 2y ago> 01983 > 01979 thats not how you write years, or even numbers really.
- buzzy_hacker 2y agoGuessing it’s from following the style of https://en.m.wikipedia.org/wiki/Long_Now_Foundation https://en.m.wikipedia.org/wiki/Long_Now_Foundation
- 38 2y ago[flagged]
- kragen 2y agosome of us post hn comments containing analyses of source code from early versions of unix, results from tracing the execution of uxn 'left' and other text editors to estimate their power usage https://news.ycombinator.com/item?id=40842397 https://news.ycombinator.com/item?id=40842397, overviews of the historical development of cpu architecture https://news.ycombinator.com/item?id=40983675 https://news.ycombinator.com/item?id=40983675, simple explanations of the role that digital signal processing plays in modern mixed-signal systems https://news.ycombinator.com/item?id=40985558 https://news.ycombinator.com/item?id=40985558, quantitative analyses of the economic and technological impact of the renewable energy transition https://news.ycombinator.com/item?id=40725765 https://news.ycombinator.com/item?id=40725765 https://news.ycombinator.com/item?id=40724305 https://news.ycombinator.com/item?id=40724305, assembly-language programs to clarify the role of associative arrays in computing https://news.ycombinator.com/item?id=40990055 https://news.ycombinator.com/item?id=40990055, analyses of mostly forgotten programming languages that python evolved from https://news.ycombinator.com/item?id=40992191 https://news.ycombinator.com/item?id=40992191, examples of how to use the gnu units program for all kinds of things most people didn't know it could do https://news.ycombinator.com/item?id=36988917 https://news.ycombinator.com/item?id=36988917, comparative benchmarks of different compilers and interpreters https://news.ycombinator.com/item?id=40960819 https://news.ycombinator.com/item?id=40960819, system call traces to elucidate subtle concurrency bugs in unix https://news.ycombinator.com/item?id=40955923 https://news.ycombinator.com/item?id=40955923, close readings of federal court rulings placing them in historical context https://news.ycombinator.com/item?id=40950806 https://news.ycombinator.com/item?id=40950806, gui libraries we wrote ourselves https://news.ycombinator.com/item?id=40942566 https://news.ycombinator.com/item?id=40942566, simple workarounds for frustrating unix problems https://news.ycombinator.com/item?id=40911681 https://news.ycombinator.com/item?id=40911681, appreciation for others https://news.ycombinator.com/item?id=40950084 https://news.ycombinator.com/item?id=40950084, recipes for video streaming from the command line https://news.ycombinator.com/item?id=40911239 https://news.ycombinator.com/item?id=40911239, admissions of error with reproducible scripts for clearly showing we were wrong https://news.ycombinator.com/item?id=40912051 https://news.ycombinator.com/item?id=40912051, helpful tips for everyday command-line usage https://news.ycombinator.com/item?id=40910845 https://news.ycombinator.com/item?id=40910845, thanks to others for correcting our errors https://news.ycombinator.com/item?id=40911035 https://news.ycombinator.com/item?id=40911035, quantitative analyses of cutting-edge hardware https://news.ycombinator.com/item?id=40903708 https://news.ycombinator.com/item?id=40903708, admissions of error in our analyses of chinese export-control regulations https://news.ycombinator.com/item?id=40885691 https://news.ycombinator.com/item?id=40885691, simple explanations of cutting-edge computer security research https://news.ycombinator.com/item?id=40885329 https://news.ycombinator.com/item?id=40885329 https://news.ycombinator.com/item?id=40841095 https://news.ycombinator.com/item?id=40841095, simple explanations of cutting-edge software testing tools https://news.ycombinator.com/item?id=40879952 https://news.ycombinator.com/item?id=40879952, and implementations in three lines of forth of things people think are impossible in forth https://news.ycombinator.com/item?id=40868981 https://news.ycombinator.com/item?id=40868981 and some of us say things like 'thats idiotic because thats 7000 years away' these are two different kinds of discourse, and this website is only for one of them
- kstrauser 2y agoWhy do you put zeroes in front of your dates?
- defrost 2y agoIt's a nod to the Long Now Foundation https://longnow.org/ https://longnow.org/ and can be taken in many ways, either as a sign of a true believer or just to invoke a sense of the scale of time beyond the immediate.
- deleted 2y ago[deleted]
- cinntaile 2y agoThose 0s in front of the year really tripped me up... I thought it was some obscure date format.