What If..... Strong Types
Lamy Jean-Baptiste
jiba at tuxfamily.org
Sun Jun 16 11:54:21 EDT 2002
> I'm not suggesting any real changes to any, only proposing a thought
> experiment.
>
> What if Python had been built from the start with strong types? And I
> mean
> strong types, not strong typing. The distinction I am trying to draw is
> that variables would not be typed, but that all types would have rigid
> interfaces.
>
> Primarily, what if classes always had rigidly defined interfaces. I
> mean
> that public members had to be declared to exist, and that methods
> couldn't be modified on an instance. Private members could exist but
> would be really private.
I've done really nice hack by changing object class, adding method or
properties, and so on... !
The object concept says that all the data of an object should be
encapsulated in a single location (=the object) rather that being spread
everywhere. Can you really speak about object if, for a given object, you
suddenly discover that you have a new property ? The right location for
that property is IN the object, so you need to add it INSIDE !
E.g. changing the class to a new one that inherit the former and add a
__setattr__ method can be used to get a callback for object modification.
There is already (too) many static language (Java, C, C++, ...) so i
believe Python must really stay dynamic !
BTW you can already have non-modifiable classes with __slots__.
Jiba
More information about the Python-list
mailing list