Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!ecngs!feeder2.ecngs.de!81.171.88.16.MISMATCH!hq-usenetpeers.eweka.nl!hq-usenetpeers.eweka.nl!bcyclone02.am1.xlned.com!bcyclone02.am1.xlned.com!newsfeed.xs4all.nl!newsfeed3a.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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python,': 0.02; 'interfaces': 0.04; 'abuse': 0.07; 'attribute': 0.07; 'puts': 0.07; 'default.': 0.09; 'expectation': 0.09; 'latter': 0.09; 'lookup': 0.09; 'referenced': 0.09; 'subject:hide': 0.09; 'url:archive': 0.09; 'violates': 0.09; 'whatever.': 0.09; 'cc:addr :python-list': 0.11; 'python': 0.11; 'def': 0.12; 'bug': 0.12; '(int': 0.16; '@property': 0.16; 'background,': 0.16; 'clear.': 0.16; 'comp': 0.16; 'file-like': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'naming': 0.16; "object's": 0.16; 'return,': 0.16; 'self.y': 0.16; 'stringio': 0.16; 'stuff.': 0.16; 'subject:Not': 0.16; 'subject:possible': 0.16; 'y):': 0.16; 'java,': 0.16; 'do,': 0.16; 'fix': 0.17; 'wrote:': 0.18; 'code.': 0.18; 'replacing': 0.19; 'thu,': 0.19; 'url:article': 0.19; 'code,': 0.22; 'cc:addr:python.org': 0.22; 'lets': 0.24; 'pointer': 0.24; 'java': 0.24; 'cc:2**0': 0.24; "i've": 0.25; 'logging': 0.26; 'somewhere': 0.26; 'header:In-Reply-To:1': 0.27; 'point': 0.28; 'function': 0.29; 'leave': 0.29; '[1]': 0.29; 'array': 0.29; 'member.': 0.30; 'message-id:@mail.gmail.com': 0.30; 'code': 0.31; 'easier': 0.31; 'that.': 0.31; "d'aprano": 0.31; 'default,': 0.31; 'everywhere': 0.31; 'steven': 0.31; 'void': 0.31; 'file': 0.32; 'class': 0.32; 'cases': 0.33; 'not.': 0.33; 'actual': 0.34; 'skip:_ 10': 0.34; 'there,': 0.34; 'could': 0.34; 'classes': 0.35; 'definition': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'add': 0.35; 'c++': 0.36; 'right?': 0.36; "didn't": 0.36; 'url:org': 0.36; 'application': 0.37; 'list': 0.37; 'remote': 0.38; 'problems': 0.38; 'skip:[ 10': 0.38; 'pm,': 0.38; 'rather': 0.38; 'url:2004': 0.39; 'itself': 0.39; 'url:12': 0.39; 'how': 0.40; 'skip:u 10': 0.60; 'most': 0.60; 'new': 0.61; 'balance': 0.61; 'simple': 0.61; 'reach': 0.63; 'guarantee': 0.63; 'more': 0.64; '30,': 0.65; 'articles': 0.65; 'side': 0.67; 'between': 0.67; 'safe': 0.72; 'to,': 0.72; 'yourself': 0.78; 'url:x': 0.81; '*network': 0.84; '2015': 0.84; 'compare:': 0.84; 'improvement': 0.84; 'member?': 0.84; 'naughty': 0.84; 'kid': 0.91; 'to:none': 0.92 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:cc :content-type; bh=uDvLBpnUUmtAmaCz+jmYsr2b5z1DTxny0bmbNiHv+7k=; b=HuX0mwdJqJWwzUiCiQNJ4sBk55v84TMoYkb54b7ixZWPNchHrsYEtyiuKPeQgR7oh7 4X1vVMqOMakFbBbF/MOwmAFNFpLbiu6KRWwQPLz1mzW1m6FaZ+QxT/5BvEEcQUvmu3hA ofPGAIlha4awtoCVn1O25P6vaL8FJsrZdPwzwcU+pQ18IAs5vJtHxyzToiCt2UcJmzcc pC0H4VCm4mmAHJquA4Oo2zbBgzTAVKP4Xh5Wsc5N5E/U1T1BZP0uIsi02pNZmh714LCs dYcJR2996HgQ6QvLASkdpaIfZM4RtH3xH2JPpyyU75+VwFhQJ6ArRlsWl+mAKk7l8wQ3 uW2w== MIME-Version: 1.0 X-Received: by 10.50.141.164 with SMTP id rp4mr1485440igb.2.1430373678514; Wed, 29 Apr 2015 23:01:18 -0700 (PDT) In-Reply-To: <87383inqut.fsf@elektro.pacujo.net> References: <874mo0zoz2.fsf@Equus.decebal.nl> <553f46d2$0$11124$c3e8da3@news.astraweb.com> <87h9rzxx5h.fsf@Equus.decebal.nl> <5541a9fc$0$13014$c3e8da3$5496439d@news.astraweb.com> <87383inqut.fsf@elektro.pacujo.net> Date: Thu, 30 Apr 2015 16:01:18 +1000 Subject: Re: Not possible to hide local variables From: Chris Angelico Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ 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: 84 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1430373680 news.xs4all.nl 2910 [2001:888:2000:d::a6]:37192 X-Complaints-To: abuse@xs4all.nl X-Received-Body-CRC: 635898147 X-Received-Bytes: 8199 Xref: csiph.com comp.lang.python:89605 On Thu, Apr 30, 2015 at 3:10 PM, Marko Rauhamaa wrote: > Steven D'Aprano : > >> If you have a Java background, you might find this useful: >> >> http://dirtsimple.org/2004/12/python-is-not-java.html >> >> http://dirtsimple.org/2004/12/java-is-not-python-either.html > > Unfortunately, I didn't find those articles all that insightful. > > The one big difference between Java and Python is interfaces vs > ducktyping. In Java, you do everything through formal interfaces. In > Python, you do nothing through formal interfaces. The other big difference between C++/Java and Python is that the former have everything hidden by default, and the latter has everything public by default. Compare: class Point { int x, y; public: Point(int _x, int _y): x(_x), y(_y) {} int get_x() {return x;} void set_x(int newx) {x = newx;} int get_y() {return y;} void set_y(int newy) {x = newy;} }; void interpolate_points(Point from, Point to, Point **target, int count) { int delta_x = to.get_x() - from.get_x(); int delta_y = to.get_y() - from.get_y(); for (int i=0;ix" everywhere in the C++ code, but that won't fix get_x. So clearly Python has the advantage, right? Well, not so clear. The philosophical abhorrence of remote mutation in C++ makes it a lot easier to reason about the code - you can look at the class definition itself and guarantee you can see every change to a private member. (Aside from naughty pointer manipulation and stuff. But in Python, we have to say "Aside from fiddling with ctypes", so this is like the Mistform Ultimus disclaimer[1].) In Python, you have to balance that in application code; is it safe to change some object's member? Can you just reach in and change the "read_callback" member to be a new function reference, or might it have been referenced somewhere else? Will you cause problems for yourself by replacing this actual file with a StringIO file-like object? How can you know? So the freedom is there, but it has to be used intelligently. ChrisA [1] eg http://archive.wizards.com/Magic/Magazine/Article.aspx?x=mtg/daily/arcana/1370 and http://archive.wizards.com/Magic/magazine/article.aspx?x=mtg/daily/arcana/1300