4 ms·
He doesn't mean literally the "|" in bash, he means the general concept.
by bo1024 14y ago
He doesn't mean literally the "|" in bash, he means the general concept.
- laumars 14y agoIn a sense, it's the same thing. He's talking about the concept of fitting things together and refers to Unix pipes (in fact the example he gave was literally a string of piped POSIX commands ready for dumping into $SHELL). My point was that this concept doesn't scale well. As a productivity tool, pipes are invaluable. But you wouldn't want to write a performance critical routine using them. At the end of the day (and as Joe said himself), it's about picking the right tool for the job.
- disgruntledphd2 14y agoWhat's the difference between pipes and chaining functions? I can't really see much difference between grep | sed |awk somestuff.txt and (awk(sed(grep(somestuff.txt))). Or are you suggesting that function composition is not the right approach? In which case, I disagree, but I would like some more insight into your thought process on this.
- anon1385 14y agoI can't speak for laumars, but I would suggest there is a difference. Functions within languages generally work at a higher level of abstraction, even in C. If you wanted a grep like function for filtering an array of strings in your programming language of choice, would you define it to take a single string and predicate arguments, that is then split up on an arbitrary character, filtered, then joined back together again to return a single string? Or would you use a general purpose filter() function that takes an array and a predicate (function pointer/lambda/block/whatever) and returns a new array?
- laumars 14y agoMy issue largely about the scalability of pipes. They're ok for basic tasks, but not great for complicated routines: 1) You've only got one send and one return. (well, arguably more if you include stderr and exit codes, but they have their own limitations in addition to the aforementioned) 2) They're too insular from each other; different files dotted about that needs to be loaded into the memory then executed. It adds quite a massive overhead. Granted this isn't an issue for the kind of jobs you'd write shell scripts for in the first place, but it does severely hamper this kind of model in terms of scalability. But then we're back to the age old issue of performance vs convenience. I will concede that the second point is more an issue about implementation rather than concept though. But if you were to write a lower level implementation of Unix pipes, I don't think it would pretty much end up with Perl functions (which, to be fair, you suggested yourself). I say Perl specifically because you can create a function without specifying what values to accept (see example below), which is akin to the 'dumb' strings read in from STDIN. sub PerlFunc() { foreach (@_) { $i++; print "Parameter $i == $_\n"; } } So I'm not really saying that pipes isn't the "right approach". Just that it isn't always the best approach. But for things like system administration, pipes are invaluable. Not just because the tools are already written (ie the wealth of command line applications), but also because it's quick to express yet highly readable. I'm not really sure if that answers your question though (or even if I've said anything you don't already know).
- kd0amg 14y agoI'm not really sure if that answers your question though I think GP was confused about the difference between the concept of piping and the concept of function composition. As noted by GGGP above, the concept of piping/composition is not only Unix pipes, but you keep arguing about that particular case of it instead of the general concept.
- laumars 14y agoThere's a reason I keep arguing about that particular case. It's because you can't really discuss the concept without examples, and as there's only really one implementation of this concept common use, the only example I can give is this particular case.
- kd0amg 14y agoas there's only really one implementation of this concept common use Function composition really isn't that uncommon.
- dragonwriter 14y agoNote that that example isn't given as an example of what would be ideal, but as a sign of the sad state of tools to fit things together that it is the best available.