[Python-il] Perl Vs. Python on Various Points
taleinat at gmail.com
Mon Jul 13 12:00:23 IDT 2009
I've used Perl much more than I wanted to, and Python extensively by choice.
> 1. Syntax as an Indicative of What the Language is Doing:
> I said I happen to like it because the extra characters convey meaning.
Perl has very few built-in types; I recall numbers, strings, arrays,
hashes and functions. When you need to use anything else you are
forced to use references, which are indistinguishable from numbers and
require "casting" their targets' values back to their actual type. You
are forced to use references for various other reasons as well (e.g.
when using hashes). My code was littered with '$', '@', '#' and '&'
symbols, many of which were required just to work with references, and
I found that this created more confusion than clarity.
> 2. Comparison Operators:
> Now python only has "==" and friends for comparison (at least as far
> as I know) while Perl 5 has both ==/!=/>/etc. and eq/ne/gt/etc. The
> first ones are intended for numeric comparison and the latter ones for
> string comparison.
First off, Python has the "is" operator which tells you whether two
variables refer to the same object. The "==" operator tells you
whether the objects referred to by two variables are considered equal,
with the meaning of being equal defined by the type of the relevant
objects. Python takes the opinion that such "deep" comparison is
usually what a programmer needs, and from my experience this is true.
Numbers and strings aren't the only two basic useful data types in
programming. When using Perl one has to look up specific functions
used for comparison of various other types of objects, even for basic
types such as arrays and hashes. In Python every class defines its own
comparison methods (if relevant), which Python uses when evaluating
"==" and friends. I can use "==" and ">=" and ">" to compare various
types of containers, such as lists, sets, tuples and dicts, and these
comparisons are simple and obvious. Besides making the code clean and
readable, things like this make learning Python less tedious.
> 3. Circular References:
I would be interested to know what kind of support Perl has for deep
comparison of containers with circular references.
> 4. Hiding Code
Usually you just don't want someone to have your original version of
the code, so they don't copy/paste and develop their own product based
on your code. For this purpose obfuscation and/or compiling to
byte-code are enough.
(Obligatory: Writing in Perl is all the obfuscation one would ever need ;)
Thanks for sharing!
More information about the Python-il