3 ms·
Looks like the tail implementation is O(N) in the size of the file. Real tools aren't (for large N anyway), and as this is a basically iterative algorithm (gue
by ajross 16y ago
Looks like the tail implementation is O(N) in the size of the file. Real tools aren't (for large N anyway), and as this is a basically iterative algorithm (guess at a suffix size, read, count, adjust) it seems like it might have been more instructive here to do it right instead of doing it pretty.
- jerf 16y agoThese aren't "real". They're "simple". It's right there in the title. You're suggesting making it a good five or ten times more complicated, and you'll still be left with problems like how not a single one of the other things there is "real" even after you've fixed tail. I'm not even sure why you chose that one in particular to focus on when grep is useless, tr only allows on substitution, uniq is bounded by memory... but the point is they are simple.
- dons 16y agoIt exposes a lot of the beautiful fundamentals of Unix when presented like this.
- jerf 16y agoTo be clear, I think this is good stuff. It's OK for a thing to be what it is; it doesn't have to be something else. Hmmm... I mean that somewhat less vacuously than English is rendering it.
- ajross 16y agoThere's a spectrum between "simple" and "wrong" though. I thought grep/uniq/tr were fine, as a correct implementation would be a straightforward extension of the code presented (well, the size bound on uniq is real, but swap storage is free these days so who care?). The tail example wasn't like that. It's the wrong algorithm. It's also in a class of algorithms that's particularly difficult in functional languages. Showing easy examples and skipping the hard stuff, IMHO, is endemic with "enthusiast" languages like this. I don't think that shows the language in a very good light.