3 ms·
Donald Knuth wrote TeX in Pascal. I think he chose it because it was the language most widely available at the time in universities where people wanted to use T
by svat 8y ago
Donald Knuth wrote TeX in Pascal. I think he chose it because it was the language most widely available at the time in universities where people wanted to use TeX; many were already using Pascal for teaching. (The first version had been written in SAIL, because it was the language available at the Stanford AI Lab where he had computer access.)
Because Pascal did not have good support for strings and variable-length arrays, TeX manages all its own memory (allocating and freeing from a single giant Pascal array called “mem”); because Pascal did not have “break” or “return” he implemented those features himself with a preprocessor and a certain disciplined use of goto; because Pascal required certain things (type declarations, labels) to be all in the same place and other things to be scattered apart, he wrote a preprocessor to rearrange sections of a program in any order; because Pascal compilers varied in their support for features like pointers and nested procedures, TeX uses only a very restricted subset of Pascal.
Real programmers do whatever it takes.
- empath75 8y agoThis essay was entirely sarcastic, in case you missed that.
- svat 8y agoOf course. But it arose in the midst of, and makes explicit and implicit references to (and fun of), many debates and attitudes that were current at the time, not just concerning programming languages but also operating systems, structured programming, goto, etc. For instance, a few months before this essay Brian Kernighan had published “Why Pascal is Not My Favorite Programming Language” (https://www.lysator.liu.se/c/bwk-on-pascal.html https://www.lysator.liu.se/c/bwk-on-pascal.html) which ends with “Pascal is a toy language, suitable for teaching but not for real programming”.
- delish 8y agoVery interesting to hear Knuth augmented Pascal significantly to suit himself. Can I ask where you found that? I'd love to read more.
- svat 8y agoSure! The entire source code of TeX has been published as a book called TeX: The Program, which is Volume B of Knuth's Computers and Typesetting series (the TeX and METAFONT manuals and source code, and the definitions of the Computer Modern fonts): https://cs.stanford.edu/~knuth/abcde.html#abcde https://cs.stanford.edu/~knuth/abcde.html#abcde The major part of the book (just the program itself, without the book's 1-page preface, 2-page bibliography, 6-page instructions on how to read the program, mini-indices on each two-page spread, 1-page diagram of approximate memory requirements, and hand-tweaked typesetting) are also available in any TeX distribution or online e.g. http://texdoc.net/texmf-dist/doc/generic/knuth/tex/tex.pdf http://texdoc.net/texmf-dist/doc/generic/knuth/tex/tex.pdf It is written using a system called WEB, and Knuth calls the idea literate programming — see article at http://www.literateprogramming.com/knuthweb.pdf http://www.literateprogramming.com/knuthweb.pdf and the WEB manual at http://texdoc.net/texmf-dist/doc/generic/knuth/web/webman.pdf http://texdoc.net/texmf-dist/doc/generic/knuth/web/webman.pd... All this is somewhat hard to read for most modern programmers IMO. In my free time I hope to make these more readable, and I've started with simply reading and annotating the simplest of the programs written in WEB: https://shreevatsa.github.io/tex/program/pooltype/ https://shreevatsa.github.io/tex/program/pooltype/ https://shreevatsa.github.io/tex/program/tangle/ https://shreevatsa.github.io/tex/program/tangle/ — if anyone reading this is interested let me know (create an issue on the GitHub repo or something).