Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder5.xlned.com!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.061 X-Spam-Evidence: '*H*': 0.88; '*S*': 0.00; 'granted,': 0.07; "'a'": 0.09; 'similar,': 0.09; 'python': 0.11; 'obj1': 0.16; 'obj2': 0.16; 'wrote:': 0.18; 'discussion': 0.18; 'variable': 0.18; 'things.': 0.19; 'later': 0.20; 'seems': 0.21; 'header:User- Agent:1': 0.23; 'java': 0.24; 'header:In-Reply-To:1': 0.27; "doesn't": 0.30; 'code': 0.31; 'existence': 0.31; 'gary': 0.31; 'names.': 0.31; 'object.': 0.31; 'languages': 0.32; 'another': 0.32; 'could': 0.34; 'objects': 0.35; 'but': 0.35; 'c++': 0.36; 'object,': 0.36; 'next': 0.36; 'subject:?': 0.36; 'to:addr:python- list': 0.38; 'fact': 0.38; 'pm,': 0.38; 'little': 0.38; 'to:addr:python.org': 0.39; 'changed': 0.39; 'new': 0.61; 'name': 0.63; 'different': 0.65; 'line,': 0.68; 'institute': 0.72; 'received:204': 0.75; 'behavior': 0.77; 'dr.': 0.77; 'subject:skip:E 10': 0.95 Date: Sat, 31 Aug 2013 00:03:58 -0700 From: Gary Herron User-Agent: Mozilla/5.0 (X11; Linux i686; rv:17.0) Gecko/20130803 Thunderbird/17.0.8 MIME-Version: 1.0 To: python-list@python.org Subject: Re: Encapsulation unpythonic? References: <8255dfbd-a2a1-4ab7-b900-ee19faa459f2@googlegroups.com> <8c7c4854-70e1-46e7-a3ff-a3206c4c5c27@googlegroups.com> <5221567b$0$6599$c3e8da3$5496439d@news.astraweb.com> In-Reply-To: Content-Type: multipart/alternative; boundary="------------000703030601060801010904" X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 101 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1377932649 news.xs4all.nl 15947 [2001:888:2000:d::a6]:57469 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:53327 This is a multi-part message in MIME format. --------------000703030601060801010904 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit 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 --------------000703030601060801010904 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit
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
--------------000703030601060801010904--