[Python-Dev] 'shadowing' builtins

Thomas Wouters thomas@xs4all.net
Wed, 19 Jul 2000 08:02:19 +0200

On Tue, Jul 18, 2000 at 04:45:19PM -0500, Paul Prescod wrote:
> 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.

No. He didn't know the scoping rules, and that was all he was worried about.
He was only confused because it didn't generate a warning when he thought it
should. Making it impossible to shadow builtins by default would confuse a
lot more people, because suddenly they can't use the variable names they
want, and they can't figure out why. "list" is a builtin ??

> 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
> (eventually!)

My code never does that. My code simply does not use 'list'. As for the
other style issues, There also wasn't a *need* to override list, it was
merely convenience. And Python is a very, very convenient language... let's
not change that :P

> > 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.

Actually, no, it depends on where and how you use it. In large programs, my
functions get larger too, on average. I'm talking 10 lines -> 100 lines
here. Also don't forget the global namespace, which affects a lot more code
in large programs. And lastly, small programs are only edited by me, or
sometimes quick-fixed by a colleague. Large programs get edited by a fair
group of people, over a number of years.

Thomas Wouters <thomas@xs4all.net>

Hi! I'm a .signature virus! copy me into your .signature file to help me spread!