Steve Edwards wrote: > Also they tend to be used more by 'non-programmers' who get away with > 'stupid' stuff like calling out to system() and piping a bunch of > commands together because they don't know how to use the language > properly :) > > I'm not disparaging Perl programmers or the language. I'm just saying > it is easier to 'abuse' a language like Perl or PHP than C. > > This Bash snippet was posted to the -users list a couple of years ago. > I'm not trying to embarrass the original programmer or trash his > skills, I'm just using this snippet as an example. We've all got > skeletons in our closets :) > > while read line; do > epoch=`echo $line | cut -d '|' -f 1` > if [ $epoch -ge $start_epoch -a $epoch -le $end_epoch ]; then > echo $line > fi > done < /var/log/asterisk/queue_log > > Note the second line. It creates a couple (2 or 3) of processes to > extract the first field from the queue_log file. For every line in > the input file! > > This kind of coding is easy in a scripting language. It would be way > more difficult in C. So much more difficult, a programmer with the > requisite skills to do it should recognize the inefficiency and do > it another way. > > If the original programmer had a better grasp of the language, he > could have coded this line as: > > epoch=${line:0:10} > > Since the Epoch will be 10 digits for the next 300 years, I'd feel > relatively comfortable with this solution. > > This single change reduced the execution time of his script by an > order of magnitude. > > Recoding it in a language more appropriate to processing lots of data > (like C) would reduce the execution time to 1/3,000th of the original. And > yes, I did it and measured it. > > A skilled programmer (like any craftsman) has many tools in his toolbox, > the experience to choose the right one, and the skill to use it well. > > C is my sharpest tool so I tend to see everything through that lens, but > I'm learning to appreciate PHP and how it lets me represent some > programming problems clearly, quickly and sufficiently efficient.
Steve, I recognized the code you posted. It's mine: <http://lists.digium.com/pipermail/asterisk-users/2009-September/237750.html> Thank goodness you didn't try to embarrass me. You just used my code as an example of how a "non-programmer" would use a language, called piping commands together "stupid" and an indication of not knowing how to use the language, referred to it as a skeleton in my closet and something that a programmer with the requisites skills and a better grasp of the language wouldn't do. I guess I am just not a skilled enough programmer to try to help someone out on this list without getting criticized by you at the time <http://lists.digium.com/pipermail/asterisk-users/2009-September/237755.html> and again almost two years later. Maybe, just maybe, it's possible that some people recognize that your crusade to replace all scripting with compiled C has its virtues, but it's not worth their programming time to save a few seconds of execution time. You've been at this for years and yet scripting languages still exist. Just think how fast Linux would boot if all of the init scripts were rewritten in C and compiled (they probably have some pipes that could be removed, too!!). Of course, it's pretty nice to be able to easily read and modify them, but execution time is all that's important, right? Your example reduced the execution time of my script by a factor of 2,700!! That's great, but do you really think if I posted C source code as a response (I could if I wanted to) to the original poster that she would have had any idea what to do with it? I'd wager that she'd spend more than the minute and a half your optimization saved pondering it before responding, "What do I do with this?" Instead, she copy-and-pasted my code, ran it, said thanks (can you believe she didn't even mention that pipe I used!!), and went on to the next thing. So which is really more efficient? Not to mention that your optimization is technically incorrect because it assumes the field is a fixed length. I'll admit, it's a valid assumption, but we're arguing technicalities here. I wonder if you'll be able to admit that sometimes optimizing a one-off script just isn't worth it? My code also has the benefit of being self-documenting. Anyone can look at it and understand exactly what it does (quite useful for a mailing list, don't you think?). On the other hand, most people will be headed straight to the Advanced Bash Scripting Guide when they see "epoch=${line:0:10}". I haven't posted here in a long time and I usually make it a policy not to get involved in or start any flame wars. Furthermore, I've always thought that your posts are intelligent and show a real understanding of the subject matter and a technical prowess. But you're out of line using other people's code as examples of bad programming techniques. Unless my code is in a directory on your desktop labeled "Bad (but in NO Way Embarrassing) Programming Examples" it would have been more efficient (see what I did there?) to come up with something on your own. And repeat after me, "Programmer time is more expensive than processor time." This isn't the 1970s anymore. Regards, Matthew Roth InterMedia Marketing Solutions Software Engineer and Systems Developer -- _____________________________________________________________________ -- Bandwidth and Colocation Provided by http://www.api-digital.com -- New to Asterisk? Join us for a live introductory webinar every Thurs: http://www.asterisk.org/hello asterisk-users mailing list To UNSUBSCRIBE or update options visit: http://lists.digium.com/mailman/listinfo/asterisk-users