Python syntax in Lisp and Scheme

Terry Reedy tjreedy at udel.edu
Sun Oct 12 17:43:38 EDT 2003


 Pascal Costanza wrote:

> I wrote:
 >> Yes, named objects, including functions can (locally) shadow
 >> (override) builtins.  It is considered a bad habit/practice unless
 >> done intentionally with a functional reason.

 > Well, this proves that Python has a language feature that is as
 > dangerous as many people seem to think macros are.

There are two reasons  to not generally prohibit overriding builtins.

1. Every time a new builtin is added with a nice name like 'sum',
there is existing code that uses the same nice name.  For 2.3 to have
broken every program with a 'sum' variable would have been nasty and
unpopular.

2. There are sometimes good reasons add additional or alternative
behavior.  This is little different from a subclass redefining a
method in one of its base classes, and perhaps calling the base class
method as part of the subclass method.

The most dangerous and least sensible overriding action, anything like
import something; something.len = 'haha'
will probably become illegal.

Terry J. Reedy







More information about the Python-list mailing list