Path: csiph.com!usenet.pasdenom.info!news.etla.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed3.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.005 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'python,': 0.02; 'say,': 0.05; 'attribute': 0.07; 'compiler': 0.07; 'from:addr:ethan': 0.09; 'from:addr:stoneleaf.us': 0.09; 'from:name:ethan furman': 0.09; 'message-id:@stoneleaf.us': 0.09; '~ethan~': 0.09; 'python': 0.11; 'def': 0.12; '@property': 0.16; 'attribute.': 0.16; 'cool.': 0.16; 'defined,': 0.16; 'pythonic': 0.16; 'received:69.93': 0.16; 'roy': 0.16; 'usage,': 0.16; ':-)': 0.16; 'wrote:': 0.18; '>>>': 0.22; 'header:User-Agent:1': 0.23; 'define': 0.26; 'header:In- Reply-To:1': 0.27; 'am,': 0.29; "doesn't": 0.30; 'class': 0.32; 'guess': 0.33; 'not.': 0.33; "i'd": 0.34; 'except': 0.35; 'no,': 0.35; 'but': 0.35; 'accessible': 0.36; 'c++': 0.36; 'subject:?': 0.36; 'behind': 0.37; 'writes': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'most': 0.60; 'received:173': 0.61; 'providing': 0.61; 'name': 0.63; 'our': 0.64; 'direct': 0.67; 'between': 0.67; 'smith': 0.68; 'article': 0.77; 'ethan': 0.84; 'furman': 0.84; 'received:gateway14.websitewelcome.com': 0.84; 'contrary': 0.95; 'subject:skip:E 10': 0.95 Date: Sun, 01 Sep 2013 13:33:25 -0700 From: Ethan Furman User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:16.0) Gecko/20121010 Thunderbird/16.0.1 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> <5221d7ab$0$6599$c3e8da3$5496439d@news.astraweb.com> <5222f675$0$6599$c3e8da3$5496439d@news.astraweb.com> <9c11126f-93e8-461c-b487-bafc6b146269@googlegroups.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - gator3304.hostgator.com X-AntiAbuse: Original Domain - python.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - stoneleaf.us X-BWhitelist: no X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: ([173.12.184.233]) [173.12.184.233]:54637 X-Source-Auth: ethan+stoneleaf.us X-Email-Count: 1 X-Source-Cap: dG9idWs7dG9idWs7Z2F0b3IzMzA0Lmhvc3RnYXRvci5jb20= 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: 61 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1378071286 news.xs4all.nl 15920 [2001:888:2000:d::a6]:38123 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:53434 On 09/01/2013 12:13 PM, Roy Smith wrote: > In article , > Ethan Furman wrote: > >> On 09/01/2013 03:09 AM, Fabrice Pombet wrote: >>> >>> So I guess that we are actually all agreeing on this one. >> >> No, we are not. >> >> "encapsulation" != "inaccessible except by getters/setters" > > Nothing is accessible in Python except via getters and setters. The > only difference between Python and, say, C++ in this regard is that the > Python compiler writes them for you most of the time and doesn't make > you put ()'s at the end of the name :-) class Javaesque: __value = None def get_value(self): return self.__value def set_value(self, new_value): validate(new_value) self.__value = new_value class ProtectedPython: _value = None @property def value(self): return self._value @value.setter def value(self, new_value) validate(new_value) self._value = new_value class PlainPython: value = None In the Javaesque class we see the unPythonic way of using getters/setters; in the ProtectedPython* class we see the pythonic way of providing getters/setters**; in the PlainPython class we have the standard, unprotected, direct access to the class attribute. No where in PlainPython is a getter/setter defined, nor does Python define one for us behind our backs. If you have evidence to the contrary I'd like to see it. * Not the best name, but oh well. ** In Python, using @property makes getter/setter usage look just like normal attribute usage, which is cool. -- ~Ethan~