Encapsulation unpythonic?

Fabrice Pombet fp2161 at gmail.com
Sat Aug 31 03:42:55 EDT 2013


On Saturday, August 31, 2013 9:03:58 AM UTC+2, Gary Herron wrote:
> On 08/30/2013 11:07 PM, Fabrice Pombet
>       wrote:
> 
>     
>     ... long discussion elided ...
> 
>       well, look at that:
> 
> a=(1,2)
> a=2+3 ->a is an object and I have changed its type and value from outside. As far as I am concerned this is one hell of an encapsulation violation... Could you do this -strictly speaking- in Java or C++?
> 
>     
>     
> 
>     Yes, in fact you can do that in C++ and java:
> 
>     
> 
>     Obj1 a = ...some object...;
> 
>     { // new scope...
> 
>        Obj2 a = ...another object...;
> 
>     }
> 
>     
> 
>     On one line, the name 'a' is bound to one object, and later it is
>     bound to another object.   Your Python code is similar, binding the
>     name 'a' to object (1,2) on one line and the object 5 on the next
>     line.  Granted, Python seems a little freer because, with it's
>     dynamic typing,  one doesn't need to create a new scope to rebind a
>     name, but all languages with variable names allow some control over
>     binding/rebinding names.
> 
>     
> 
>     But this has *nothing* at all to do with objects and encapsulation.
> 
>     
> 
>     Please don't confuse:
> 
>     the binding of names to objects and
> 
>       
> 
>       the existence of objects and their encapsulated behavior
> 
>     
>     They are very different things.
> 
>     
> 
>     -- 
> Dr. Gary Herron
> Department of Computer Science
> DigiPen Institute of Technology
> (425) 895-4418

That's interesting, can you do this in C++ or java:

class X():



More information about the Python-list mailing list