considering moving to python....
I've read up a little on python, and it looks like a great scripting language. In the past I've done all my scripts with Perl or Bash, but Python looks like a great alternative. I love the simplicity of the scripts, the great readability, and the fact that it's OO.
So, my question is this... is Python a viable alternative to Perl? I love the fact that Perl is so extensible (CPAN) and that the community is large, but the language can be pretty cryptic at times, and it's hard for me to remember all of the logistics of the language (I'm more familiar with PHP, Java, and C). I intend to use Python for text processing, and for basic console utilities.
Anyways... enough rambling, clue me in to why this language is so great, and why it's not!
I programmed in Perl for several years before I discovered Python, and I have never regretted switching. The functionality provided by many of the libraries that you find in CPAN are either unneccessary in Python, or are included in the standard libraries. There is also the Python Package Index (PyPI) which is a similar repository to CPAN, plus the Vaults of Parnassus.
IMHO Python is both more readable and writeable than Perl - it is easier to write in Python because you don't have to remember lots of special cases and contexts. I find when I am programming in Python I can concentrate on solving the problem at hand, rather than wrestling with the language.
There is one area where I would still consider using Perl - writing zero-length scripts with the -e 'command' option, usually in conjuction with -p or -n. e.g.
perl -p -e "s/perl/python/" *.txt
to do a search and replace, or
perl -n -e "print if /fish/ && /chips/" *.txt
to grep for lines that contain both the words "fish" and "chips". My rule of thumb is that if a script is too long to put on the command line, then write it in Python.
I recommend that you read the article by Open Source guru Eric Raymond on his experience in switching from perl to python: http://www.linuxjournal.com/article.php?sid=3882
Dave - The Developers' Coach
Also coming from a perl background - i'm often surpised how many Python users are - i think theres alot to be said for both languages and there are parts i like from both i.e. the built-in regex in perl. Since i picked up Python a year or so ago i havn't touched perl at all (well maybe once or twice ) and i've never been happier .
So yes Python is definatly a good alternative to perl; admitadly the community is smaller than that of perls right now but IMO much friendlier and generally more willing to help.
Put simply... Pythons mix of eligant, clear syntax and power; in the form of its rich standard library and builtin types and functions etc. really do lend themselves intuativly to nearly anything you might want to do with them! And whats more you'll find yourself having more fun too.
If your ever worried about preformance you can easily write exentions in C/C++ or Java (using Jython). You can also try one of the many different tools which can be used to boost Pythons speed i.e. Psyco. Although personally i've never had any problem in this area!
Dont take our word for it though - try it yourself, or - go right to the source and ask Yoda what he thinks .
But seriously, give it a go and you wont regret it... or i've never met anyone who has so .
Last edited by netytan; May 1st, 2004 at 09:17 AM.
Thanks for the responses! I actually did read the article by Eric Raymond late last night after posting. Excellent article, but he had one unexplained statement that made me curious:
"For tiny projects (100 lines or fewer) that involve a lot of text pattern matching, I am still more likely to tinker up a Perl-regexp-based solution than to reach for Python."
Why is this? Are regex faster in Perl, or just easier to code?
Perl was built to manipulate text and its built-in regex are a powerful asset... not because they are faster than in Python but simply because they are always available (where as in Python the re library must be imported) and are supported as a key part of the language itself, hence perl is better by design for this kind of work; in popular oppinion.
The reason Eric mentioned the 100 line limit is because more often than not when your perl programs lengh reaches 100+ lines it becomes fairly difficult to manage go figure .
Hope this clears things up,