{"id":10766,"date":"2022-08-26T13:47:03","date_gmt":"2022-08-26T17:47:03","guid":{"rendered":"https:\/\/irreal.org\/blog\/?p=10766"},"modified":"2022-08-26T13:47:03","modified_gmt":"2022-08-26T17:47:03","slug":"red-meat-friday-knuth-versus-mcilroy","status":"publish","type":"post","link":"https:\/\/irreal.org\/blog\/?p=10766","title":{"rendered":"Red Meat Friday: Knuth versus McIlroy"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">One of our cherished stories, at least of one of <em>my<\/em> cherished stories, is the account of <a href=\"https:\/\/matt-rickard.com\/instinct-and-culture\">Don Knuth and Doug McIlroy solving the same problem<\/a>. The problem was<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>Given a text file and integer k, print the k most common words in the file (and the number of their occurrences) in decreasing frequency.<\/p><\/blockquote>\n\n\n\n<p class=\"wp-block-paragraph\">The TL;DR is that Knuth wrote a 10 page WEB program to solve the problem while McIlroy solved the same problem with a 6 line Unix shell script.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You can imagine the lessons that were drawn but they all omit a crucial bit on context: Knuth was asked to demonstrate literate programming by solving the problem so McIlroy\u2019s solution wasn\u2019t really on-point.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">These days whenever the story comes up the usual reaction is to cry foul because of that missing context\u2014here\u2019s a <a href=\"https:\/\/www.reddit.com\/r\/programming\/comments\/wk7m2c\/knuth_and_mcilroy_approach_a_problem\/\">representative example<\/a>\u2014but I draw a different conclusion and always have. The two solutions represent two ways of approaching a problem: (1) write a program <em>de novo<\/em> to arrive at a solution or (2) leverage existing software to solve it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Many of us\u2014me included\u2014tend to reach for Knuth\u2019s solution first and even think of the quick and easy shell solution as cheating. That\u2019s silly, of course. The point is to solve the problem not to write code. Yes, in the particular case of the story, Knuth\u2019s answer was the best one but usually, absent other special circumstances, McIlroy\u2019s is clearly superior. It\u2019s worth remembering that we have tools other than the hammer of writing code and that not every problem is a nail requiring that hammer.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>One of our cherished stories, at least of one of my cherished stories, is the account of Don Knuth and Doug McIlroy solving the same problem. The problem was Given a text file and integer k, print the k most &hellip; <a href=\"https:\/\/irreal.org\/blog\/?p=10766\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[208],"class_list":["post-10766","post","type-post","status-publish","format-standard","hentry","category-general","tag-rmf"],"_links":{"self":[{"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/10766","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=10766"}],"version-history":[{"count":1,"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/10766\/revisions"}],"predecessor-version":[{"id":10767,"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/10766\/revisions\/10767"}],"wp:attachment":[{"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10766"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10766"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10766"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}