[BiO BB] Python or Perl

Ann Loraine aloraine at gmail.com
Sun Jan 21 01:11:59 EST 2007


Hi,

Here are my two cents:

If it's fair to compare computer languages with human languages, then perl
is  English, and Python is esperanto.

I've used perl and python both. During my postdoc and later at my first
couple of jobs, I wrote a lot of Perl code for building Web pages (CGI) and
for data-processing/mining tasks. My fellow programmers were all using Perl,
so I just went along with what they were doing.

After about five years of that, I decided to try out Python. I wanted to
take advantage of some functionality I could get from python's 're' (regular
expression) object that I couldn't so easily get from Perl. I think what
attracted me to Python was how easy it was to get an re object to give me
all matches in a given string, or something like that.

Back then it only took me a couple of days to learn it well enough to get
work done, i.e., learning the syntax, figuring out how to configure my
system, setting up emacs, and so on.

I think that for total beginners, python takes less time to learn than perl,
and other people's Python code is generally easier to understand because the
syntax is more limited and generally seems less freaky. When I was first
learning Perl (after already having learned Java), I was a bit put off by
having to put punctuation signs in front of variable names and also by all
the weird-seeming global variables like $_ and so on. With python, it seems
as though you have to keep less stuff in your head, and that let's you focus
on the logic of what you're trying to do rather than remembering a lot of
arcana.

Both perl & python have pretty much all the third-party tools you would be
likely to need -- code for talking to databases (e.g., MySQLdb) and XML
handling, for example. Biopython has parsers for blast reports and reading
fasta records, plus most of the other functionality of bioperl. (But I could
be wrong on the latter point -- it's been years since I knew bioperl well.)

Python's interactive interpreter makes programming a lot easier. You define
functions in files called "modules", load them into into the interpreter
environment using  import or reload, and then run them. If you forget all
the variables you've defined, you just run the "dir" command. You can also
write a "main" method if you want and run script-like programs that way, but
I hardly ever do that.

The interpreter makes it easier to do science, because you can read data
into the environment and interact with it. You don't have to re-write and
re-run your scripts (as with Perl) every time you want to answer a simple
question about a data structure.
These days, it seems plain wrong to me to build up a data structure in
memory and then lose it once the program terminates.

Writing and using new object classes is also nicer in Python than in Perl,
but again, this may have changed since I last worked with Perl. (I think I
stopped using it around Perl5 or so.)

It's nice to to be able to cope with both languages, of course, because
sometimes you run across some-one else's code that you might want to use,
and you might need to modify it. Also, there's a very nice Oreilly book on
blast that has a lot of perl code examples. A fun exercise for people who
know both would be to translate the examples into python.

Good luck and don't forget that computing should be fun!!!

Ann

-- 
Ann Loraine, Assistant Professor
Departments of Genetics, Biostatistics,
Computer and Information Sciences
Associate Scientist, Comprehensive Cancer Center
University of Alabama at Birmingham
http://www.transvar.org
205-996-4155



More information about the BBB mailing list