On 9 May, 08:09, "Hendrik van Rooyen" <[EMAIL PROTECTED]> wrote:
>
> I am relatively new on this turf, and from what I have seen so far, it
> would not bother me at all to tie a name's type to its first use, so that
> the name can only be bound to objects of the same type as the type
> of the object that it was originally bound to.

But it's interesting to consider the kinds of names you could restrict
in this manner and what the effects would be. In Python, the only kind
of name that can be considered difficult to arbitrarily modify "at a
distance" - in other words, from outside the same scope - are locals,
and even then there are things like closures and perverse
implementation-dependent stack hacks which can expose local namespaces
to modification, although any reasonable "conservative Python"
implementation would disallow the latter.

In a local namespace you could restrict names in this way, although
I'd argue that with the limitations on locals, you don't gain as much
as you would by restricting other names similarly. However, by
restricting other kinds of names (eg. instance attributes) you have to
start thinking about polymorphism: what if attribute x on instances of
class C can have different types? If you aren't careful, you've
introduced interfaces as the primary mechanism permitting some kind of
polymorphism.

Paul

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to