Why the 'self' argument?

Delaney, Timothy C (Timothy) tdelaney at avaya.com
Mon Sep 8 18:58:47 EDT 2003


> From: John Roth [mailto:newsgroups at jhrothjr.com]
>
> > Also I think that the class members should be explicitly 
> declared. In
> > general, it would be nice to have an option (like Option Explicit in
> > Visual Basic) so that you can't assign to variables that 
> have not been
> > declared. It would probably make Python less error prone.
> 
> I believe that is what __slots__ is for. That's run time rather than
> compile time, but at least it gives you the error on the statement
> that attempts to do an invalid assignment.

I think you badly misunderstand the purpose of __slots__. __slots__ is not designed to restrict the capabilities of a class (although some people misuse it that way). The sole use case for the introduction of __slots__ was to improve performance and memory usage.

Personally, I think every class other than the built-in types should have an implicit __dict__ entry in __slots__ to remove this misunderstanding ... (only populated if actually accessed ...).

Unfortunately, Explicit is better than Implicit ... ;)

Tim Delaney





More information about the Python-list mailing list