4 ms·
I think that's the full and whole point of the article: The unix command line tools can be combined by a mediocre systems engineer to do the work of Knuth in le
by vessenes 11y ago
I think that's the full and whole point of the article: The unix command line tools can be combined by a mediocre systems engineer to do the work of Knuth in less time and with easily assessable correctness.
This is a form of wonderful magic, available only because of the discipline and vision of those who wrote the original tools.
- fenomas 11y agoBut Bentley chose the program. He chose a task that's suited to a few lines of shell and asked Knuth to apply Literate Programming to it. Complaining that the result is overworked seems disingenuous - like asking someone to apply the MVC pattern to fizzbuzz and then asking why they used such a verbose approach to such a simple problem.
- lisper 11y agoIt's possible that Pascal libraries, if they existed, could be combined in a similar fashion. It's possible that Knuth's code was in fact written in that way so that if you really compared apples and apples, the unix solution would be seem like a horrible hack because it had to use two different programming languages.
- vessenes 11y agoMaybe, but pascal didn't actually come with a batteries included piping concept. You'd need to work one up. Well, you could abuse the GNU pipes library and get your piping that way maybe by running it through the OS, but that would definitely not be how Knuth rolls. As a side note, I think the shell script version would have been multicore friendly, at least up to six cores. I am sure Knuth's was single threaded. Finally, to your point on horrible hacks, maybe Knuth's version dealt with a whole bunch of edge cases in each, like for instance dealing with dos/unix/mac endlines. But, probably not -- it was a toy program written as evangelism and out of courtesy. sort and uniq et al embed many programmer lifetimes of experience and bug fixing at this point. Getting all of that nearly for free is really, really great.
- pascal_cuoq 11y ago> As a side note, I think the shell script version would have been multicore friendly, at least up to six cores. That's not how the sort command, in lines 3 and 5, works.
- regularfry 11y agoIt is how pipelines work, though. 6 commands, 6 processes all started at once. They're each allowed a core to themselves, if the kernel deems it so.
- davidshepherd7 11y agoBut `sort` has to read all the input before writing any output (I think...). So you get some parallelism but not as much as you might hope.
- lisper 11y agoThat's true, but it doesn't really count if only one of the threads is eligible to run at any one time and all the others are blocked.
- lisper 11y ago> pascal didn't actually come with a batteries included piping concept No, it has function calls instead. > I think the shell script version would have been multicore friendly Not unless 'sort' is implemented very cleverly. > maybe Knuth's version We'll never know unless someone manages to dredge up the source code. But the specifics on Knuth's version are not really the point. Someone else might have been able to do better. And someone using a less brain damaged language that Pascal might have been able to do even better. In fact, here it is in four lines of Common Lisp (using Ergolib - https://github.com/rongarret/ergolib https://github.com/rongarret/ergolib): (defun histogram (path) (bb l (split (file-contents path) t :test (fn (a b) (whitespacep b))) l (sort 'string< (mapcar 'string-upcase (remove "" l))) (for item in (remove-duplicates l) collect (list item (count item l))))) Writing a pure CL version is left as an exercise. My guess is it would be 10-20 LOC.
- reagency 11y agoOK, now tell whose technique is more likely to lead to TeX or Google Brain: Knuth's Literate Programming, or McIlroy's "everything worth doing is already a Unix built-in"?
- gnaritas 11y agoMcIlroy's, because he'll finish; that's kind of the point, good engineers ship and reuse as much as possible. Look at all the work of DJB[1], nearly everything he does is just a bunch of well tied together shell scripts. [1] https://en.wikipedia.org/wiki/Daniel_J._Bernstein https://en.wikipedia.org/wiki/Daniel_J._Bernstein
- deleted 11y ago[deleted]