syntax philosophy

Andrew Dalke adalke at mindspring.com
Tue Nov 18 19:40:05 EST 2003


Tuang:
> That use of Perl for one-liners, though, is why having them be easy,
> automatic, and memorable matters. That's why I would prefer the same
> convenience in anything I use to replace Perl for "Swiss Army knife"
> use. I would apparently have to give up a bit of the convenience at
> the one-liner level to buy the superior scaling (and other relative
> benefits) of Python.

One thing to consider is Python's interactive nature means you don't
have to do everything as one-liners.  For more complicated cases where
I would have done a one-off one-liner I now start up Python and
to things step-by-step.  Python is *not* a good shell substitute, though
PyShell does help a lot, judging from the demo I saw.

> I find Perl's defaults to be right almost *all* of the time.

That is true, but only works because of weak types and typed
operations.

> Increment a counter?  Fine, $counter++ creates the counter if it
> needs to be created, initializes it if it was just created, and then
> increments it.

And your use of ++ tells it to be a number.  I agree that Perl
puts a lot of flexibility into just a few characters.

> On the rare occasions when I want it initialized to something
> other than 0, I just initialize it myself, but the default
> initialization of zero is right almost all the time for numbers, so
> why not take advantage of that fact?

It doesn't initilize to 0, I think it initializes to undef.  It's only
when you do ++ or += 1 where the undef gets converted into
an integer.  You can test it out by doing ' .= "X"' instead of ++.
It should not start with a '0', which it would if the default value
was 0.

> Amen. But $hist{$word++} works beautifully.

Especially if you typed it correctly ;)

> Thanks. That perfectly explained the philosophy behind my example.

You're welcome.

                    Andrew
                    dalke at dalkescientific.com






More information about the Python-list mailing list