[Python-Dev] 'shadowing' builtins

Paul Prescod paul@prescod.net
Tue, 18 Jul 2000 16:45:19 -0500

Thomas Wouters wrote:
> ...
> My first reaction was 'Ack, eek, argh, nonono'. So I decided to sleep over
> it. And my reaction is still 'Ack. eek, argh, nonono' ;) If it's optional,
> like a '-ww' option, sure. But by default ? Please don't. One of python's
> great features is that it's so damned consistent. Having some builtins
> overridable and others not would not only break a lot of code, it would also
> confuse a lot of people.

Most people probably do not even know that the built-in functions can be
shadowed. That's precisely the problem. I don't think that enforcing a
rule that they expect to already be enforced will confuse them. As your
friend pointed out, NOT enforcing the rule confuses them.

> There is no particular reason to disallow assigning to map() for programs
> where map() is not used, for instance. I often find myself doing 'list =
> <...>' for small scripts, eventhough I realize while I'm typing that 'list'
> is a builtin function. Part of the reasons is that 'list' is an incredibly
> descriptive name, and my code often gets read by colleagues who still need
> to get infected by the Python virus.

Using the same word for two different things is more likely to confuse
them than help them. Anyhow, constructor  functions and type names need
to be unified (for consistency) and type names and class names need to
be unified (for consistency). And class names start with an upper case
letter. So the need to override list() is scheduled to go away

> Nevertheless, I wouldn't do that in large projects, and that's where I
> invision the '-w' option would be best used. 'This might become a problem'.

It is just as likely a problem in a small project than ina a big one.
The shadowing is local, after all. It isn't a problem that "gets worse"
as the program grows.

 Paul Prescod - Not encumbered by corporate consensus
Just how compassionate can a Republican get before he has to leave the 
GOP and join Vegans for Global Justice? ... One moment, George W. Bush
is holding a get-to-know-you meeting with a bunch of gay Republicans.
The next he is holding forth on education or the environment ... It is
enough to make a red-blooded conservative choke on his spotted-owl
drumstick.     - April 29th, Economist