Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!newsreader4.netcologne.de!news.netcologne.de!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.108 X-Spam-Level: * X-Spam-Evidence: '*H*': 0.79; '*S*': 0.00; "'a'": 0.09; 'python': 0.11; '"a"': 0.16; '2);': 0.16; 'garbage': 0.16; 'tuple': 0.16; 'wrote:': 0.18; 'appears': 0.22; 'aug': 0.22; 'email addr:gmail.com>': 0.22; 'creating': 0.23; 'integer': 0.24; 'refers': 0.24; 'java': 0.24; '>': 0.26; 'second': 0.26; 'header:In-Reply-To:1': 0.27; 'tim': 0.29; 'returned': 0.30; 'statement': 0.30; 'message-id:@mail.gmail.com': 0.30; 'code': 0.31; 'object.': 0.31; 'another': 0.32; 'fri,': 0.33; 'to:name :python-list': 0.33; 'could': 0.34; 'objects': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'object,': 0.36; "i'll": 0.36; 'subject:?': 0.36; 'two': 0.37; 'list': 0.37; 'skip:& 10': 0.38; 'to:addr:python-list': 0.38; 'explain': 0.39; 'does': 0.39; 'to:addr:python.org': 0.39; 'changed': 0.39; 'major': 0.40; 'new': 0.61; 'simply': 0.61; 'first': 0.61; 'name': 0.63; 'taking': 0.65; 'statement,': 0.68; 'reflection': 0.84; 'subject:skip:E 10': 0.95; 'you).': 0.95; '2013': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=2sLZ0SCsJn+nNyxtGYiRO/PzyNKUY8ol8ozjMk6PivE=; b=QTHGRDhHnNIuACMnY32ejdqoexRGap+/pgFjPmRNSgIIyIyS5VUgnZnRUDK06/ndp3 TuFplM8uApQ0qvgfqUVOzH/5EoMRf9s+0rlBewHYe15PtyHA++p0anzpnQd2pilUhBZb qRgvrrAdQBaii/HmmXpiHBEB+CPLpLviPwBq2BvjfdqF5cGvtVEMv1ncb7raB3iru9Sc 4TP9O+/KZiFUFFPTET93xUJBlEefmbKVXTVc9MivVloB1wgjQK+oE2WtZid38ryUus0j iRpb5pEBSw152wmSwcfgLaLZAKzfdVgUpapEVg84Oy6Gb9dG0gSYWbsj9yU0KgZp+9dk itMw== MIME-Version: 1.0 X-Received: by 10.60.60.105 with SMTP id g9mr11272556oer.8.1377971242425; Sat, 31 Aug 2013 10:47:22 -0700 (PDT) In-Reply-To: References: <8255dfbd-a2a1-4ab7-b900-ee19faa459f2@googlegroups.com> <8c7c4854-70e1-46e7-a3ff-a3206c4c5c27@googlegroups.com> <5221567b$0$6599$c3e8da3$5496439d@news.astraweb.com> Date: Sun, 1 Sep 2013 03:47:22 +1000 Subject: Re: Encapsulation unpythonic? From: Tim Delaney To: Python-List Content-Type: multipart/alternative; boundary=089e0149d0ae6a691e04e541ee89 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: 92 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1377971252 news.xs4all.nl 15996 [2001:888:2000:d::a6]:48486 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:53372 --089e0149d0ae6a691e04e541ee89 Content-Type: text/plain; charset=UTF-8 On 1 September 2013 03:31, Dennis Lee Bieber wrote: > On Fri, 30 Aug 2013 23:07:47 -0700 (PDT), Fabrice Pombet > > declaimed the following: > > >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++? > > There is where your major misunderstanding is... > > "a" is a NAME attached (bound) to an object. In the first statement, the > object is the tuple (1,2). That object was not changed when you execute the > second statement -- which is taking two integer objects and creating a new > integer object having a value of '5', and then attaches the NAME "a" to the > new object. If no other names are bound to the (1,2) object, it will be > garbage collected. > I'll try another way to explain it, using Java terminology(since Fabrice appears to be familiar with Java). Object a = Arrays.asList(1, 2); // a is a reference to the List returned by Arrays.asList a = Integer.valueOf(2 + 3); // a is now a reference to the Integer returned by Integer.valueOf You have not changed the type of 'a' in any way - you have simply changed what the name 'a' refers to. This is functionally identical to your Python code above,except that in Python you do not have to downcast the Object reference 'a' or use reflection to call methods on it or access it's members (think of it as Python does reflection automatically for you). Tim Delaney --089e0149d0ae6a691e04e541ee89 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
On 1 September 2013 03:31, Dennis Lee Bieber <wlfraed= @ix.netcom.com> wrote:
On Fri, 30 Aug 2013 23:07:47 -0700 (PDT), Fa= brice Pombet <fp2161@gmail.com&g= t;
declaimed the following:

>well, look at that:
>
>a=3D(1,2)
>a=3D2+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 viol= ation... Could you do this -strictly speaking- in Java or C++?

=C2=A0 =C2=A0 =C2=A0 =C2=A0 There is where your major misunderstandin= g is...

"a" is a NAME attached (bound) to an object. In the first stateme= nt, the
object is the tuple (1,2). That object was not changed when you execute the=
second statement -- which is taking two integer objects and creating a new<= br> integer object having a value of '5', and then attaches the NAME &q= uot;a" to the
new object. If no other names are bound to the (1,2) object, it will be
garbage collected.

I'll try another= way to explain it, using Java terminology(since Fabrice appears to be fami= liar with Java).

Object a =3D Arrays.asList(1, 2);= =C2=A0// a is a reference to the List<Integer> returned by Arrays.as= List
a =3D Integer.valueOf(2 + 3); =C2=A0// a is now a reference to the Int= eger returned by Integer.valueOf

You have not chan= ged the type of 'a' in any way - you have simply changed what the n= ame 'a' refers to. This is functionally identical to your Python co= de above,except that in Python you do not have to downcast the Object refer= ence 'a' or use reflection to call methods on it or access it's= members (think of it as Python does reflection automatically for you).

Tim Delaney
--089e0149d0ae6a691e04e541ee89--