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 :)

On Mon, 11 Jul 2011, cbul...@gmail.com wrote:

I understand your point but I don't share it.... There are a lot Asterisk-Perl project working in production environment.

Then I didn't communicate my point clearly.

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.

--
Thanks in advance,
-------------------------------------------------------------------------
Steve Edwards       sedwa...@sedwards.com      Voice: +1-760-468-3867 PST
Newline                                              Fax: +1-760-731-3000

--
_____________________________________________________________________
-- 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

Reply via email to