5 ms·
Related: http://www.leancrew.com/all-this/2011/12/more-shell-less-egg/ TLDR: Donald Knuth and Doug McIlroy both wrote a program that would read a textfile
by wwweston 11y ago
Related:
http://www.leancrew.com/all-this/2011/12/more-shell-less-egg/
TLDR: Donald Knuth and Doug McIlroy both wrote a program that would read a textfile, determine the n most frequently used words, and print out a sorted list of those words along with their frequencies.
Knuth's was 10 pages of (very tightly/well written/literately documented) Pascal.
McIlroy's was tweetable:
tr -cs A-Za-z '\n' |
tr A-Z a-z |
sort |
uniq -c |
sort -rn |
sed ${1}q
Now... a programmer doesn't always have the luxury of working with a full suite of convenient tools well-suited to their problem domain (as UNIX shell tools were in this case), and the merits of Knuth's careful and literate approach can serve well across many domains.
Still, there's something about this I think should strike any developer. It seems we talk about reuse & composability a lot more than we see it done this well, and when it is done this well it's not just elegant but kindof shocking.
(And I bet the astute FP programmers see some familiar lessons at work here...)