Thinking Pythonically (was Re: gah! I hate the new string syntax)
f8dy at diveintopython.org
Sat Mar 3 08:06:52 CET 2001
in article 97q14l$jbi$0 at 126.96.36.199, Donn Cave at donn at oz.net wrote on
3/3/01 12:57 AM:
> I have no idea what it's like to use Visual Basic, I have never
> even heard of Powerbuilder.
Heh heh, I'd love to go back to my previous employer and quote you on that.
They thought Powerbuilder was the right tool for every job.
> verbose by comparison. Many people love Perl. You may find that
> you do, too, there's no reason to expect otherwise. But it's
I have had just enough experience with Perl to know that I don't want any
> important to recognize that there is a huge crowd of people who
> swim upstream to use Python instead, and it's not just because
> we have to be different, it's not because we want to use Zope
> or our boss twisted our arm to write in Python. It's certainly
> not because Python is more powerful, in the sense you have been
> talking about.
Oddly enough, my current boss did twist my arm to learn Python, but I
realize that that's the exception. But I do now understand better why
people have called my coding style "dense" (meaning "too tightly packed"),
"line noise", etc. Coming from Perl, I guess Python would be a breath of
fresh air precisely because it's more verbose, less dense, more readable.
But I came at Python from a different angle, after years of being forced to
use inferior, less powerful, less expressive languages which we were pushing
beyond their limits. (We had to write code from scratch to parse the
command line, because there was nothing like sys.argv. We had to write
Windows API calls to get a directory listing because we had no os.listdir
and the only built-in function to do it would only put the results into a
graphical listbox. We had no regular expression parsing whatsoever. Etc.)
I love that, in Python, I can write in three lines of code what would take
an entire page in Powerbuilder. If you want to quibble and say that it
would be more Pythonic to write it in four lines of code, that's fine, we
can both happily co-exist.
> know, I guess it's not for everyone, but for myself, I want to
> challenge your notion of what it is to think Pythonically.
Actually, to me, rich data structures are a minor part of thinking
Pythonically; they're just what the original example was about in this
thread. A much more important part is introspection, which I cover in depth
in chapter 2 of my book (http://diveintopython.org/apihelper_divein.html).
Looking back on it now, I can't believe I ever put up with a language where
you had to choose between dynamically constructing a method name and getting
a return value (*); where you couldn't find out what methods a class had;
where you couldn't get access to the stack trace when something went wrong.
(*) Fellow Powerbuilder survivors will remember that TriggerEvent, which
allows you to call an event by name, doesn't return the event's return
value, and all other ways of calling a method require you to know the method
name at design time. If you were wondering why I poke fun at Powerbuilder
in my book, that's why. That, and the
directory-listing-into-a-graphical-listbox function; that was classic.
You're smart; why haven't you learned Python yet?
More information about the Python-list