A most important, but also most elusive, aspect of any tool is its influence on the habits of those who train themselves in its use. If the tool is a programming language this influence is, whether we like it or not, an influence on our thinking habits.
There certainly can be good reasons not to uselessly use cat, and getting into the habit of doing so can be a bad thing, especially if your code is likely to be used as a bible by relatively uninformed users (as yours is).
I work at a place where relatively uninformed users routinely set up large, super-high-bandwidth pipes on compute clusters using cat, in which case cat may waste significant CPU (what's the block size that it's reading from disk, I wonder?). Furthermore, cat gives you a one-way stream as output, so downstream apps don't have the ability to get information about the original file (such as size) or to seek back and forth. In general, streams < files.
The end result is that my carefully written C code with all its carefully optimized seeking behavior ends up wasting hours burning through hundreds of terabytes of unneeded data just because it doesn't have a seekable input descriptor, and then the users complain that their code is slow and after debugging I find that they're doing this junk and remind them (again!) not to do this, and then two months later they copy some code off of yet another blog like this and yet again don't notice that the cat is not necessary and yet again complain that their code is slow...... etc.
So yeah, I guess I feel like if I wrote a blog claiming to be anything resembling a how-to, I'd try to write pretty good code, just to be nice and not give people bad ideas. But it's your blog of course, and your call.
I am being sponsored by Syntress! They bought me an amazing dedicated server to run catonmat on. If you're looking web services, I highly recommend the Syntress guys!
Education Sponsors
I am being sponsored by A-Writer! If you ever need help with essay writing, look no further than A-Writer! They will help you with your writing in as quickly as 3 hours!
There certainly can be good reasons not to uselessly use cat, and getting into the habit of doing so can be a bad thing, especially if your code is likely to be used as a bible by relatively uninformed users (as yours is).
I work at a place where relatively uninformed users routinely set up large, super-high-bandwidth pipes on compute clusters using cat, in which case cat may waste significant CPU (what's the block size that it's reading from disk, I wonder?). Furthermore, cat gives you a one-way stream as output, so downstream apps don't have the ability to get information about the original file (such as size) or to seek back and forth. In general, streams < files.
The end result is that my carefully written C code with all its carefully optimized seeking behavior ends up wasting hours burning through hundreds of terabytes of unneeded data just because it doesn't have a seekable input descriptor, and then the users complain that their code is slow and after debugging I find that they're doing this junk and remind them (again!) not to do this, and then two months later they copy some code off of yet another blog like this and yet again don't notice that the cat is not necessary and yet again complain that their code is slow...... etc.
So yeah, I guess I feel like if I wrote a blog claiming to be anything resembling a how-to, I'd try to write pretty good code, just to be nice and not give people bad ideas. But it's your blog of course, and your call.
Reply To This Comment