From Perl to Python



 While working for the Unix systems administration group at Lewis & Clark College I first started to learn Perl scripting.  Having come from C I thought Perl was nothing less than amazing.  Finally, strings could be copied around like strings, memory issues were virtually non-existant and the language was so forgiving of mistakes that I thought I had reached the nirvana of programming.  

After leaving college I got a job at a public school district where I wrote my first large scale application in Perl.  I was the sole author and the application was a CGI program which used a backend Microsoft SQL database to show student standarized test scores.  At this point I was getting pretty decent with the language and the application was a huge success.  By the time I moved onto my job at Intel I was the resident expert.  I was teaching classes, attending perl trainings and buying every perl book that was written.  

It was into my fifth year of working at Intel that I started to lose my infatuation with Perl.  It was not so much with the code I was writing (or so I would like to believe) but rather after five years of debugging badly written Perl code by others I was seeing the same basic same issues coming up time and time again.  Errors from not checking return values on system calls, using uninitialized values, system calls for built in perl commands, and on an on and on.  Perl's regular expression language is the the best there is but in some ways it is too easy to use.  I saw people using regular expressions for *everything*.  (One person used it in place of the Perl 'eq' comparator as " if ($dog =~ /^$cat$/) {}".  The problem here occured as $cat gets processed as part of the regular expression.)  

Most of the time the person writing the code knew what they were doing was wrong but they just seemed to not care.  "Why read a directory when `ls` works in fewer lines?"  It is just too tempting to go bad, especially when no one is watching.


While I was having my awakening with Perl I came across the programming language of Python.  I had heard of the language before, but back then I had been so mesmerized with Perl that I brushed off Python as a a "nice try" when compared to Perl.  I started to play around a bit with Python and as I was attending school at the time for my Masters, I decided to do my class projects in Python.  I realized that Python was a far better group language than Perl.  Exceptions and warnings in Python were all on by default where as they had  been optional in Perl.  This meant that you could no longer claim ingorance for a basic error like a bad system call.  Either you handled the error, or it halted the script.  You could still tell Python to ignore the error, but now you had accountability.  Where as Perl had Base and AUTOLOAD, Python had a real inheritance structure which  just worked better.  Plus, after lecturing people time and time again about needing to do some sort of indenting in their code, Python's required indentation came as a breath of fresh air.  Python looked like executable pseudo code.

These days I still give Perl trainings when asked and I still write some quick scripts here in there in Perl, but for any big scripting projects I will always try to use Python first.  People should be creative as to how they solve their problems, not in how they write their code.