Why should I switch to Python?
James Felix Black
jfblack at uswest.com
Thu May 11 15:58:13 EDT 2000
> The only explanation for this that I can think of is that you're a
> lot smarter than I am!
Oh, I don't know about that. I've got a /lot/ of perl state in my
brain -- I've been programming perl for eight years. Not that that
kept me from making a mistake in the code I posted, though. Ah, the
hubris ...
> It's getting stuff *out* of the data structures that I find to be
> radically different.
Yes. This is due to the dichotomy between first-class variables and
references, and it's a confusing problem for people, I can see. And
that doesn't even begin to cover such horrendous things as typeglobs.
> for $f (@{ $friends{ $name } }) {
Ok. Let me redo the code (and get it /right/ this time!).
%friends = ( Bob => [ ], Jane => [ "Lisa", "Mabel", "Freddy" ],
Lisa => [ "Mabel" ] );
# note that I had to change the braces to parens in the assignment to
# a hash: curly braces return a /reference/ to a hash -- when you want
# a "real" hash, you need to use parens. if you ran the code as it
# originally was posted, you'd get a hash with one element (the hash
# reference { Bob => [ ] ... }. Which is illegal. mea maxima culpa!
for $name (keys %friends) {
print "$name has these friends:\n";
for $f (@{ $friends{ $name } }) {
# ok. in the hash (dictionary) %friends, the value associated
# with the "$name" key is a reference to an array. However, the
# for operator expects a list to iterate over. therefore, we
# have to dereference the value of $friends{ $name } back into a
# list: we do this with the @{ } construction.
#
# man, that's weird looking.
print " ", $f;
}
print "\n";
}
After I sit back and look at this, I realize just how strange dealing
with perl's references is. To me, of course, it's natural: but for
someone just looking at doing some scripting, I can totally
empathise. I'm just so numbed by looking at things like:
$var{ foo }[ bar ]("baz");
all day long that I occasionally lose sight of how strange that is.
There're a couple of things about python I wish were different, but I
have to say that the language is astonishingly readable and
straightforward: no nasty little "gotchas." And threads (and signals)
appear to function properly.
Hmmm.
(jfb)
--
To spur "enterprise Linux," Big Bang, the distributed two-phase commit.
More information about the Python-list
mailing list