"?:", "a and b or c" or "iif"

Robert Meegan Robert.Meegan at wcom.com
Tue May 25 15:06:22 EDT 1999


On Tue, 25 May 1999, Fred L. Drake wrote:

[Erudite response to Hans-Christian Holm omitted]

> 
>   I don't think there's a good way to do this in Python right now; we
> have to use an if in the context where we need the result:
> 
>      if x:
>          result = a
>      else:
>          result = b
> 
> (Unless, of course, we happen to like some of those hideous constructs 
>   Perhaps Python 2 can fix this shortcoming; I'd often like to use
> something equivalent to ?:.
> 

As someone who is decidedly not from a computer science background, I believe
one of Python's strongest points is the simple elegance of the language. Time
and again people identify a feature of another language and decry how Python
requires you to implement it using the primitive tools available. IMHO, these
people may be missing the point of writing in Python.

Python is a very simple language. This simplicity means that when you look at a
code segment, it is almost immediately apparent what the author intended. When
you see the code segment that Fred wrote above, there is very little room for
confusion. Similarly, when you find a "while 1:" construct, it is pretty obvious
that the author intended the code to run until interrupted, whether internally
or externally.

While it is always possible to add new features to a language, it is almost 
impossible to remove them later. Rather than have a feature or keyword that is
used infrequently by most people, but which must be learned by all, isn't it
better to require a few additional lines of code? After all, we live in the
golden era of cut and paste and global search and replace. It's easier to let
our code editors do a little extra work when we write the code than to have to
spend more time ourselves when we are called upon to revise or repair old code.

Viva simplicity!
--- Robert


--------------------------------
Robert Meegan
MCIWorldCom - Cedar Rapids, Iowa
319.375.2416






More information about the Python-list mailing list