True/False story... (PEP 285)

Alex Martelli aleax at aleax.it
Tue Apr 9 05:41:47 EDT 2002


Petr Prikryl wrote:
        ...
> you crazy ;) In other words, if the expression
> ``28+bbb()`` is used in the numeric context
> (determined by the plus operator) I would prefer

Good attempt, but there's a fundamental misunderstanding
of Python's worldview here (and in the rest of the post)
as evidenced by "numeric context determined by the plus
operator".

Python does not work by operators determining contexts:
that's *Perl*'s way, and Python is poles apart (and we'd
like it to stay that way).  + can mean numeric addition,
or concatenation of strings, or of list, or tuples --
that depends on the OBJECTS the operator + is applied to.

Python is object-oriented, not context-oriented.

Control structures (including the two that masquerade
as operators, 'and' and 'or') and certain statements
(such as print) do in some measure define a context
which may imply asking the object for type conversion:
iter(x) is implied by "for y in x:", bool(x) [when
bool is introduced] by 'x and y' -- note however that
in the latter case the bool() is only used in an
auxiliary way, since 'x and y' MUST return x itself,
NOT bool(x), if x is taken as true... so, viewing it
in terms of type conversion is nowere as useful as it
is for print (where str() is implicitly called AND
its result is indeed what gets used) and the for loop
(where iter() is implicitly called AND its result is
indeed what gets used).

I think the PEP's conceptualization as booleans as
a subclass of int is a better approach than one
hinging exclusively on context.  You say that booleans
cannot be conceptually compared to integers -- but,
there IS a natural mapping of booleans onto a subset
of integers, just as there is a natural mapping of
integers onto a subset of reals (or rationals, etc).

Not that it makes much practical difference at this
point, with PEP285 accepted anyway, but I'm now going
to switch to defending the pep's overall stance (even
though I'd have, a little bit, preferred it had never
happened:-) given that the alternatives that might
be still open are IMHO worse.


Alex




More information about the Python-list mailing list