Dijkstra on Python

Roy Smith roy at panix.com
Tue Aug 13 06:53:21 EDT 2002


"James J. Besemer" <jb at cascade-sys.com> wrote:
> This minimalist philosophy does perhaps have some merit in, say, designing
> the syntax of the language.  E.g., Perl goes overboard IMO with the various
> ways to test a condition:
> 
>     if( x ){ y }
>     y if x;
>     x && y;
>     x || y;

I agree 105% that having an alternative form of the "if" statement in 
perl is utterly brain-dead.  It's different for the sake of being 
different, and adds no value that I can see.  But, if you're going to 
pick on perl's "x || y" idiom, keep in mind that you *can* do exactly 
the same thing in python:

>>> 0 or sys.stdout.write('got here\n')
got here
>>> 1 or sys.stdout.write('got here\n')
1

it's just a side-effect of a perfectly common and reasonable feature 
(short-circuit evaluation) which many languages share.  The big 
difference between perl and python WRT this idiom is mostly cultural.  
In the perl community, "defined(foo) || die ('no foo')" is considered 
standard usage.  In the python community, you'd probably get shouted 
down if you tried to write the above as anything other than:

>>> try:
...     foo
... except NameError:
...     sys.stderr.write ('no foo\n')
...     sys.exit(1)
...
no foo



More information about the Python-list mailing list