Re: [vox-tech] Uses for Perl
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [vox-tech] Uses for Perl
On Sun, Jun 10, 2001 at 12:57:38AM -0700, Eric wrote:
> I don't know a whole lot of either language, but I
> hear for larger projects Python is great (and actually
> much more suitable/scaleable than Perl), for quick and
> dirty type tasks (sysadmin stuff) Perl can't be beat.
> I guess it depends on if you want to be more of a
> programmer (Python) or a *nix Sys Admin (Perl). Java
> is fairly hot also and is being used in a lot of
> industrial strength middleware, if I have my facts
> straight... (and just to muddy the waters a bit).
I have enough knowledge on Python and Perl to comment on this one.
I don't really consider either Python or Perl very stable. I recently
went through Oreilly's Learning Python book, and was impressed by a
couple things, and very unimpressed by some other things. I learned
it because (a) I'd been meaning to, and (b) I'm on a development group
whose project (a kewl RPG) is written in C++, but is mostly scripted
Here are my current thoughts comparing the two:
- I don't see why everyone in the Python development world seems to
thrive on comparing themselves with Perl - they really don't fit
into the same applications, in my opinon. I especially would much
prefer Perl over Python in any circumstance that would involve lots
of regular expressions. Python's expressions are now just as
powerful as Perl's; but they're a module, not built-in language
syntax, and so it's substantially quicker to use Perl's.
- Python has equivalents to pretty much all the Perl
text-processing-related builtins ('cept regexes, of course).
- Python has a feature that I've missed a lot lately in Perl,
actually, and that is that strings are still lists of characters,
just like they are in C. You can either treat it as a whole string,
or as a list of strings by applying iterative methods on it or
something. There are times in Perl where I want to iterate through
all characters in a string, and either end up having to use the
substr() builtin, split() or unpack() to generate an array of
characters. This is an annoyance, and in my mind, there is a
problem when something, no matter how small, is actually easier to
do in C than it is in Perl. Here's a comparison of how I might do
such iteration in the two languages:
for my $character (split //, $the_string)
for character in the_string
Note that the above Perl version also generates a new list, using
extra space, where the Python version doesn't.
- I very much dislike Python's scoping rules - there is no lexical
scoping. At any time, only three scopes exist: the local scope, the
global scope, and the builtins scope. What this means is that if
you have several nested scopes, the innermost one will not be able
to see the namespace of its immediate parent; only it's own scope,
and the global one. This has various very impractical consequences
which I shall not get into here.
- Python certainly can look very pretty with it's OOP-centric design
philosophy (I don't think anyone can deny that Perl's OOP support is
a massive hack).
- Perl has a lot of very helpful "syntactic sugar" - this can be a
boon if you know it, but can make readability hard for newbies
perhaps. I like it a lot, personally.
- Perl has a variety of ingenius scoping devices that other languages
have not discovered yet. I love Perl's 'our' keyword, which allows
you to declare an global variable which is locally scoped. Other
'our's in different scopes but declaring the same name access the
same variable, but the visibility of that variable is limited to the
scope of the 'our' statement. 'local' lets you create a temporary,
local version of a global variable. I can't think of other
languages that have anything like this, and it helps to prevent a
lot of the problems that global variables have.
For myself, overall, I would jump to use Perl for most text-processing
related tasks. Nothing beats Perl regexes. And it's scoping rules
are much more palatable. But I would use Python for large
XML-processing (very powerful XML modules), and GUIs. And because of
it's readability, I think the place where it really shines is as a
"glue" language; which is the purpose for which I learned it.
Somehow, I think I favor Perl overall. Could just be that I'm more
used to it.