4 ms·
It is elegant, and easy to understand and modify. But it's less efficient and significantly slower than even a naïve python or perl script since it sorts a lot
by tyingq 3y ago
It is elegant, and easy to understand and modify. But it's less efficient and significantly slower than even a naïve python or perl script since it sorts a lot more than it needs to.
- taeric 3y agoMe thinks we see different naive python on the regular. Because I wouldn't be shocked to see many flat out failures. That said https://www.amazon.com/Exercises-Programming-Style-Cristina-Videira/dp/0367350203 https://www.amazon.com/Exercises-Programming-Style-Cristina-... is a good sized book that is nothing but takes on this program from different styles. It is amusing how far you can take that. Which... is kind of the point of the Knuth solution here. It was a pedagogical exercise. As much to show how literate programs can be presented as it was to "solve" the stated problem. Edit: It occurs to me you could be referring to the pipeline version. Which, yeah, I don't think that really changes my post. :D. The final paragraph would be changed to the point of the Milroy's code is to get the answer, not to have a library function that is expected to be used again and again on input.
- tyingq 3y agoYes, I was talking about the pipeline version. Last time this came up, I tried a simple perl script[1] and it was quite a lot faster than the pipeline. Even without using a heap to further limit the sorting. [1] https://news.ycombinator.com/item?id=30038415 https://news.ycombinator.com/item?id=30038415
- im3w1l 3y agoI think it will be faster than python or perl, because the actual work is done by optimized c-code. However if you want to extend the program from a toy to something that can handle words like "won't" "c-code" "a.i." or "naïve" then it will be quite difficult to do so.
- tyingq 3y agoI tried a perl script versus the shell pipeline, see my other comments in the thread. It's significantly faster, because using sort and uniq -c is a pretty high effort way to count words, especially for big lists. Your words seem to work fine with it, it's just splitting on whitespace.
- tuatoru 3y agoThat'd be a problem if it were to run a million times a day or on exabytes of data. But it's a "nonce": to be used once, on a small desktop machine (for low-integer values of once). That's not really a good objection.
- tyingq 3y agoIt's not an objection, it was an observation.
- jjgreen 3y agoI was appalled when I first heard a colleague use "nonce" in this manner, I'd only previously heard it used as slang for sex-offender/paedophile, https://www.collinsdictionary.com/dictionary/english/nonce https://www.collinsdictionary.com/dictionary/english/nonce
- tyingq 3y agoThat use of "nonce" supposedly comes from a once used acronym associated with some segregated prisoners..."not on normal courtyard exercise".