"def" vs "sub" (was RE: More random python observations from a perl programmer)
tchrist at mox.perl.com
Fri Aug 20 09:01:09 EDT 1999
[courtesy cc of this posting mailed to cited author]
"Tim Peters" <tim_one at email.msn.com> writes:
:There are real barriers for native speakers of
:either language in picking up the other.
What do you think falls into this category? What thing
about Python makes it hard for a native speaker thereof
to learn Perl, and vice versa?
[massive closure generator deleted]
:This one is more interesting than it looks <wink>: in the last version of
:Perl I tried it on, it leaked memory at a prodigious rate.
Absolutely. You've a circular reference there.
:The reason it's
:interesting is because it's faking pretty much what Python would have to do
:to support lexical closures,
I'm not sure why you say "faking".
:In Python and in Perl (at least in the Perl I last tried that under) that
:creates cyclic garbage: makefac's lexicals have to contain a binding for
:fac, and fac has to point back to makefac's lexicals in order to resolve
:up-level references. And that's (unrecoverable trash) the reason Python
:doesn't have lexical closures today.
That's quite right. Doesn't python have some similar issue related
to the use of bound methods?
:Whereas Python has no warnings of any kind -- it it's irked enough at me to
:complain at all, it's irked enough to kill me. In that it's a faithful
:reflection of Guido's personality <wink>. Seriously, I do prefer that.
perl -w is "pardon me, but are you really sure you know what you're
doing there?", it's not "die die die, you ignorant script kiddie!".
:As a native speaker of Python, -w and "use strict" decorate all my Perl, and
:in the few Official Perl projects I've been on "NO WARNINGS!" was an
:absolute rule. The more fatals the better.
That's how I virtually always programmed it. Sometimes I don't bother
on little one-liners that turn Perl into Super Sed, like
perl -i.orig -pe 's/^(\d+)/$1 + $./e' file1 file2 file3
# add current line number to each number that occurs at
# the front of a line, and put changes back in place,
# backups into file.orig
But real programs get -w and use strict always. After all,
just as with /* Lint Happiness */ of days of old, I know
how to temporarily rescind them if I really am convinced
that I really do know what I'm doing.
:> What does Python do at compile-time?
:It's too busy desperately scrounging for excuses to kill your program with a
:bogus SyntaxError to do anything useful <wink>. About the only compile-time
:optimization is that function locals (in the absence of "exec" and "import
:*" statements) are mapped to consecutive indices into a contiguous runtime
You, Tim, might someday look at the interesting tricks that the Perl
compiler and interpreter go through about storage, speed, and tacit reuse
of my() variables (lexically scoped locals). Remember that my() in Perl
is one of Perl's four declarations, something then that the *compiler*
knows about, and can take suitable actions based up static analysis.
(And I nearly never mean the (C or byte)-code-generating backends when
I say "compiler" in a Perl context. I just the guy who does the parsing
in the previous paragraph.)
I remember my frutration as a flaming C advocate (you didn't really
think I started with Perl, did you? :-) getting a job at a company
that made US$75k Fortran compilers being told that Fortran would always
be faster than C because the fc compiler could know more things about
your code than the cc compiler could, and thus make better compile-time
optimization to speed run-time. I wonder whether Python simply hasn't
matured as far as Perl has along those lines, or whether in fact there
are inherent barriers, as there are between Fortran and C. What do you
think? I also notice that Python is bereft of compiler pragmata.
:"exec" and "import *" can alter the *set* of local names, so their presence
:inhibits that optimization.
Aren't you glad you don't have Tcl's "upscope" naughtiness?
People sometimes ask for this in Perl, to be able pop up a level
into your dynamic caller's private lexical scope? I'd rather have
:So, no matter what anyone here tells you, Perl doesn't have a monopoly on
:being cute & repulsive at the same time <0.8 wink>.
Oh, I know. It's the new converts who are scariest. The adage that
one should "beware the man of one book" becomes "beware the programmer
of one language" in our world, or should that really be "the zeal of
fresh converts burns annoyingly"? :-)
Timesharing: the use of several people by the computer
More information about the Python-list