Python order warts (and others)

David Mertz mertz at gnosis.cx
Fri Nov 22 15:38:30 EST 2002


Alex Martelli <aleax at aleax.it> wrote previously:
[...'<' used to be an order relation, but isn't now...]
|Why comparing string 'plak' with the number 23 is OK, but comparing it
|with 23j isn't, kind of escapes me -- but apparently property (2) was
|deemed less desirable than the ability to forbid e.g. comparing 23j with
|42j.  To the point of changing Python's previous behavior, no less:-(.

I think this change is the worst wart that has been added to Python
since I've been using it (about 4 years).

I think--as Alex does--that the "print >> FILE" form was a mistake.  But
it is just ugly syntax, and I've even found myself using it
occassionally.

Likewise, I think that the syntax whereby you create a generator by
using the 'yield' statment somewhere deeply buried inside a function is
a bad choice.  I would much rather see that feature right in the
function declaration, perhaps by using the word "gen" or the like in
place of "def".

Actually, it would not break anything (much) to add the pseudo-keyword
'gen' as an alternative word.  In this case, presumably, using the 'gen'
keyword would -require- you to also put a 'yield' inside the body (or
raise an exception).  This would not break existing code, but would
provide a path to improving future code by encouraging explicit 'gen'
declarations.

But those warts are only matters of syntax.  I might have spelled those
things differently, but there is no deep semantic issue.  The
"incommensurability of complex numbers" is a much worse semantic
problem.  I used to be able to sort lists, now I cannot.  Or at least
without first checking all the contents of the lists before I try to
sort (or maybe catching errors and recovering somehow).  It's ugly.

In my book, I suggest a bit of a workaround for readers.  It's not
wholly fleshed out, but it points in a possible direction.  Take a look
at:

    http://gnosis.cx/TPiP/chap1.txt

Jump to the discussion of:

    BUILTIN -- complex : New-style base class for complex numbers

I would welcome better or more complete solutions, of course.

Yours, David...

--
    _/_/_/ THIS MESSAGE WAS BROUGHT TO YOU BY: Postmodern Enterprises _/_/_/
   _/_/    ~~~~~~~~~~~~~~~~~~~~[mertz at gnosis.cx]~~~~~~~~~~~~~~~~~~~~~  _/_/
  _/_/  The opinions expressed here must be those of my employer...   _/_/
 _/_/_/_/_/_/_/_/_/_/ Surely you don't think that *I* believe them!  _/_/





More information about the Python-list mailing list