4 ms·
The ‘useless cat’ shtick is dumb. Unix command line is based on connecting programs in pipelines. The first step of a pipeline like that is handing the file to
by aasasd 6y ago
The ‘useless cat’ shtick is dumb. Unix command line is based on connecting programs in pipelines. The first step of a pipeline like that is handing the file to a filtering/processing util (or whatever else). Like, if I decide to use awk instead of sed, I shouldn't have to dance around the ‘<file’, because the ‘<file’ is the first step and awk/sed is the second.
(Edit: another comment provides a different example: putting in ‘cat’ instead of ‘head’—or often, switching back and forth a couple times.)
The ‘useless cat’ bunch of dorks are just astoundingly oblivious to the actual interface of the system. Instead, their argument is the hilariously nitpicky ‘omg one more process, it's so slow’. Did running a ‘cat’ really take more time in '95 than fiddling around the ‘<file’?
- Alupis 6y agoIt's no more "dumb" than pointing out to people they don't need to do something like: `if (something == true) { return true; }` It's about understanding what the system does, and why. It makes you a better systems administrator in cat's case, or a better programmer in the return true case.
- aasasd 6y ago> makes you a better systems administrator Better because you move past the ‘<file’ every time you decide to correct the first command in the pipeline? Such better, wow.
- dllthomas 6y agoI mean, if you're concerned about the keystrokes, learn your editing shortcuts. Jumping to the beginning of the line is typically one or two keystrokes. But the parent obviously wasn't talking about the behavior of avoiding useless cats making you better, but the understanding that drives the recognition of which cats are useless and why you might want to avoid them. I'm... not sure about that claim, fwiw. On the one hand, I see a lot of people really mushy on the unix process model, what pipes are, how redirection works, etc. Firming that up is important, will lead you to be a better sysadmin and a better programmer if you work in a sufficiently unixy environment (and possibly otherwise), and spotting useless cats falls out of it. On the other hand, caring about useless cats is not a necessary consequence. Caring might motivate understanding... but might just lead to overfitting a bunch of poorly understood patterns to avoid the label. So I am skeptical. But you should respond to the claim actually made.
- garaetjjte 6y ago<file is allowed to be at front (for some reason it seems counterintuitive, but '<file grep foo' is valid) Still 'useless use of x' complaining doesn't make much sense for me, unixy tools are generally used in pipelines, using separate tools makes each step more clear, easier to modify pipeline. I don't have to skim through pages of extra grep/whatever tool manual just to check if it maybe reimplemented wc -l
- aasasd 6y ago> unixy tools are generally used in pipelines Yeah, for this reason I won't write ‘<file’ at the front even though I've heard of it before. I'm in the Unix game for good command-line pipelines among other things, and bending over backwards to sidestep the pipeline isn't really in my plans.
- dllthomas 6y ago<bucket hose | hose | hose vs hose <bucket | hose | hose
- dllthomas 6y agoSomething I like about putting my redirections at the front is that if I pull this out into a function there often is no redirection, or the redirection will take the form of an `exec` on an earlier line. In either case, keeping the redirection out of the pipeline proper makes that transformation easier.
- deleted 6y ago[deleted]
- dllthomas 6y ago> Did running a ‘cat’ really take more time in '95 than fiddling around the ‘<file’? It does now for a sufficiently large file. And it's even more extreme when the recipient can do things with a file that it can't do with a pipe. Which isn't to say it's worth bitching about the rest of the time. Edited to add a silly example: $ time cat /dev/zero | tail -c +5000000000 | head -c 10 | xxd 00000000: 0000 0000 0000 0000 0000 .......... real 0m2.808s user 0m0.348s sys 0m4.849s $ time </dev/zero tail -c +5000000000 | head -c 10 | xxd 00000000: 0000 0000 0000 0000 0000 .......... real 0m0.006s user 0m0.008s sys 0m0.004s
- paulryanrogers 6y agoYeah big files need all kinds of fun special attention like ripgrep or zgrep
- vCponEt3kuFMT3F 6y agoFirst, we shouldn't be insulting people for having different opinions on the nuances of command line tools. Secondly, I agree with you that "useless use of x" should not be viewed as dogma and people shouldn't stress too much about it. Instead, these can be viewed as optimizations, or just details regarding how unix shells and tools work that can help inform your coding. IMO, the best thing to do when writing shell scripts, regardless of skill level, is configure ShellCheck in your text editor's linter, and then do everything it tells you to do: https://github.com/koalaman/shellcheck/ https://github.com/koalaman/shellcheck/
- canjobear 6y agoIndeed. Unix philosophy is many tools that all do one small thing well. Cat handles opening a file and sending it to another file. I start pipelines with cat whenever possible, in case later on I have to drop in zcat or similar instead. The other examples given in the article also demonstrate that they have completely failed to understand not only Unix philosophy but also basic readability. For example, preferring the cryptic `something | grep . >/dev/null && ...` over `something | grep '..*' | wc -l`.
- srean 6y agoI always used to wonder what kind of attitude has been making new software slower and slower, now I know. There are people who write Turbo Pascal and there are people who insult others for pointing out waste and inefficiencies in a program. The former writes software that's stays relevant and leaves behind a legacy. Not so sure about the latter. Granted that it is easy being latter.