tchrist@convex.COM (Tom Christiansen) (01/28/91)
I didn't realize it at first, but I seem to have stumbled upon a possible religious issue. It has to do with two different approaches to problems. I really think this software engineering issue -- hence, the cross-posting. One of these involves taking an input stream and performing repeated mungings on the stream using various UNIX filters. The alternative is to re-order the algorithm to place the locus of control at the center of a loop within some kind of script. I've come to believe that the first approach is, for many problems that people try to use it on, simply too slow, awkward, and difficult to under- stand when compared with the other approach. One correspondent believes that these two methodologies are completely interchangeable. Others believe one or the other to be superior. I'm interested in some non-inflammatory, theoretical discussions on this. In a way, it reminds me of functional programming versus other styles. Here was the task that got this all started: write a ``which'' that displays each possible path rather than just the first one. My version (well, the shell one at least :-) was this: for dir in `echo $PATH | tr : ' ' `; do test -x $dir/$1 && echo $dir/$1 done Another poster, who now lives in my global kill file because I got fed up with abusive rhetoric when what I really wanted was some discussion on the relative merits of the two methodologies, proposed essentially this: ls -dFL `echo "$PATH" | tr : '\012' | sed -e "s:\$:/$1:"` | sed -ne 's/*$//p' (but you have to throw away stderr) I'm willing to be convinced otherwise by reasonable persuasion, but to me, the 2nd method seems to me more complex and hard to maintain. While it does run slower than the first way, but that's not the real point. I'm looking at maintainability and complexity. If you were grading on style, what would you look for? My gut feel is that solutions like #2 are good for job security, but bad for convincing people that you don't have to be a wizard use UNIX. I think some problems are simple enough for approach #2, but for more complex ones, while you *can* hammer #2 into working for you, #1 is better for the reasons stated. --tom -- "Hey, did you hear Stallman has replaced /vmunix with /vmunix.el? Now he can finally have the whole O/S built-in to his editor like he always wanted!" --me (Tom Christiansen <tchrist@convex.com>)