problems with Perl; changing to Python

Michael Gilfix mgilfix at eecs.tufts.edu
Thu Apr 18 14:00:21 EDT 2002


  Hiya. I did the same switch myself not too long ago. I tend to
use Python now for my general purpose programming and am much
happier with it than perl. I've written large programs in perl and
manage an OS projects that has over 10000 lines of perl (check out
http://peep.sourceforge.net) or Net::Peep on CPAN. I'll interperse
comments through out...

On Thu, Apr 18 @ 19:22, Uwe Mayer wrote:
> Perl is great for scripts. Perl is great for programs with less than 
> perhaps 200 lines. A program should be aware of its memory usage; for a 
> script I don't care.

  I'm not sure I agree with this statement so you should be weary of
that assertion. Perl can be fine for large programs but you have to
be disciplined (i.e, always 'use strict' and avoid using ridiculous
constructs). However, perl cannot currently compile to bytecode and
thus has a long start up time for large applications.

  Perl has also done a lot of stuff right that Python is still solving
in its infancy. Take the perldoc system for example or the maturity
of something like CPAN. The beauty of perl is that there is a CPAN
module for almost anything... not so for python.  However, the python
standard library is considerably richer than the perl standard library
IMO.

  The nice thing about python is that the syntax is always clear and
causes people to use a similar style when writing scripts, making
things easier to understand. Your programs tend to be much more
maintainable as a result. Python also compiles to bytecode (can even
do some optimizations) and executes that byte code in the interpreter,
much the way java processes byte code as well. And there's more but
I'll address your specific issues.

> I need a language that can be used to write programs with. GUI, and 
> commandline tools. When the program run in background they shouldn't 
> take up more memory than necessary.
> F.e. I wrote a Perl script checking for changes on homepages, expiry 
> date, etc in regular intervals. This "program" is 600 lines long and 
> uses 7mb of ram... too much in my oppinion.
> Can I do that in Python?

  I have written several gui tools in python. Never in Perl
though.  There are several gui packages. Some come with python as
standard, such as Tkinter (which is very portable but not very
featured). Alternatively, you can use wrappers around packages such as
pygtk (around GTK) or wxPython (around wxWindows).

  I don't find that python programs hog memory. It really depends on
how you construct your app. Like all interpreted languages, you will
have the overhead of loading the intepreter into memory but I don't
think that's really of any import.

  Using lines of code to gauge memory usage isn't very
useful. Depending on what you're doing, a simple 5 line program can
use up gobs of ram. I think python is more efficient than perl though
as everything in python uses references, and not so in perl.

> I'll need to write programs which have to be extensible. The program 
> may, during calculation require up to 500 mb ram. Fine with me. On the 
> other hand I'll neet to write something working in background and then 
> (depending on its task and size) 1-2 MB should be enough. 
> What about Python here?

  You'll love python here. Python classes are easily extensible and very
maintainable. Easy to add new features to classes. I'm not sure what you
mean about ram vs. extensibility though. If you mean memory management,
then that all depends on what sort of task you're doing and is very
much program dependent.

> Installing Perl modules was a torture. I am sitting behind a firewall 
> and in order to install the modules (compiling them did never work on my 
> Windows 2k mashine) I had to run my own DNS server and tunnel the 
> connection. Will that work better with Python? (f.e. Proxy support would 
> be sufficient!)

  Well, python supports modules but doesn't have a CPAN. Packaging
of python modules was introduced recently (roughly as of 2.0 or so)
and we're still getting that stuff straight. But you can very easily
download any package and install it. Many programs work this way
(install their libraries into the site-package directory). I've also
never had any problems using python on win32. Never tried perl though.

> And for the GUI programming: I used Perl/Tk previously, so Tkinter would 
> be most fammiliar, I guess. What other GUI packages can Python offer me 
> that will work (perhaps even in compiled .exe format) on windows 
> mashines? What about features like "minimize to tray" or "always on 
> top" that I wasn't able to accomplish in Perl/Tk?

  Think I answered this but again: pygtk and wxPython are obvious choices.
If you're programming in windows (and you sem to want to), then wxPython
is the way to go. It has all sorts of features that Tk doesn't include.
I highly recommend it.

> I need a language where I can rely on OOP if I need to. A language where 
> there's a difference between class- and instance- varriables. 
> How about multiple inheritance (perl, c++) or interfaces (jave) in 
> python?

  Python uses OOP extensively and using clean syntax (not like the
hack that is OOP in perl). Inheritance is very straight-forward and
understable.  You can also do multiple inheritance and although there
is no "interface" concept, it's easy to write an abstract class that
accomplishes the same thing.

> Are there any applications written in Python?
> Am I right here with Python or will I have to stick to a hybid C++/Java 
> solution?

  Sure. Go to sourceforge.net and search for python apps. I have
a 5000 GUI ftp program myself (ftpcube.sourceforge.net) that uses
pygtk. Has some outdated screenshots if you want to check it out.
Doesn't run on windows yet since the windows port of GTK doesn't
support threading but runs nicely on all *nixes. I have some others
that I've written for research - particularly a graphing program using
wxPython.

  Obviously with my propaganda, I'm supporting python over
C++/JAva. I'm not a big fan of Java since I feel that the language is
clunky (from a programming perspective). You might also want to
check out the Jython project as it might interest you.

  Hope that helps.

              -- Mike

-- 
Michael Gilfix
mgilfix at eecs.tufts.edu

For my gpg public key:
http://www.eecs.tufts.edu/~mgilfix/contact.html





More information about the Python-list mailing list