Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!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; 'patterns': 0.04; 'one?': 0.05; 'c++,': 0.07; 'patterns.': 0.07; '"class"': 0.09; 'constructor': 0.09; 'hiding': 0.09; 'oh,': 0.09; 'worse': 0.09; 'python': 0.11; 'agreed,': 0.16; 'extension,': 0.16; 'factory': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'gained': 0.16; 'practices.': 0.16; 'roy': 0.16; 'exception': 0.16; 'sat,': 0.16; 'language': 0.16; 'wrote:': 0.18; 'trying': 0.19; 'saying': 0.22; 'logical': 0.24; 'skip:% 10': 0.24; "i've": 0.25; 'meeting': 0.26; 'second': 0.26; 'header:In- Reply-To:1': 0.27; 'function': 0.29; 'chris': 0.29; 'am,': 0.29; "doesn't": 0.30; 'message-id:@mail.gmail.com': 0.30; 'code': 0.31; 'struct': 0.31; 'void': 0.31; 'class': 0.32; 'another': 0.32; 'skip:_ 10': 0.34; 'received:209.85': 0.35; 'received:209.85.220': 0.35; 'something': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'c++': 0.36; 'keyword': 0.36; 'possible': 0.36; 'received:209': 0.37; 'stopped': 0.38; 'to:addr:python-list': 0.38; 'anything': 0.39; 'does': 0.39; 'bad': 0.39; 'to:addr:python.org': 0.39; 'called': 0.40; 'smith': 0.68; 'article': 0.77; 'compare:': 0.84; 'subject:skip:o 10': 0.84; 'yourself?': 0.84; '2013': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:content-type; bh=u3qROQZExWGTO0HLDUXYCnDQ9VTXVGfwGzhWOe3mJXc=; b=MxtqCsZH2ZJcEbuao9L6tuzSep7tXS2YPYi64TM4nUgPzITaRKzhyr6Zhf01ed+oZU zC6wKqhFN33j+5RUtFAgE3VWVz8FKbKS9sGte6EL3BLd0AQNgmeLcFMcpIwsftJR5AGq gcme6PgjBBkUbDlMJr72CjTNUjS0YIrJy+lRgeZaoufV0SZfBd85LQPFj3Mi73gfouzL WwsnU4s8Q32qeHg+XMeDj6a9JMuiC4S7kcr3iY8vmIjdE/TGIDWkXHwHmhVAk990p196 pYXUmmau65gXc88MmeKMeesaCEZ2bB+GD0vQDFVCtSyEQHgbiC8C4/yZEeb5e7ICKvPa UBwg== MIME-Version: 1.0 X-Received: by 10.52.231.231 with SMTP id tj7mr9721590vdc.111.1368198544390; Fri, 10 May 2013 08:09:04 -0700 (PDT) In-Reply-To: References: <518a123c$0$11094$c3e8da3@news.astraweb.com> <518b32ef$0$11120$c3e8da3@news.astraweb.com> <518be931$0$29997$c3e8da3$5496439d@news.astraweb.com> <518c5bbc$0$29997$c3e8da3$5496439d@news.astraweb.com> <518c7f8e$0$29997$c3e8da3$5496439d@news.astraweb.com> <518cd360$0$29997$c3e8da3$5496439d@news.astraweb.com> Date: Sat, 11 May 2013 01:09:04 +1000 Subject: Re: object.enable() anti-pattern From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 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: 53 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1368198547 news.xs4all.nl 15972 [2001:888:2000:d::a6]:44024 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:45104 On Sat, May 11, 2013 at 12:54 AM, Roy Smith wrote: > In article , > Chris Angelico wrote: > >> On Sat, May 11, 2013 at 12:37 AM, Roy Smith wrote: >> > I suppose, if I had a class like this, I would write a factory function >> > which called the constructor and post-construction initializer. And >> > then I would make the constructor protected. >> >> That sounds like a reasonable plan, with the possible exception of >> protected. Since meeting Python, I've stopped using private and >> protected anywhere. >> >> ChrisA > > Each language has its own set of best practices. Trying to write C++ > code using Python patterns is as bad as trying to write Python code > using C++ patterns. Agreed, in generality. But what is actually gained by hiding data from yourself? Compare: class Foo { int asdf; public: Foo(int _asdf):asdf(_asdf) {} int get_asdf() {return asdf;} void set_asdf(int _asdf) {asdf=_asdf;} void frob() {printf("Hi, I am %d\n",asdf);} }; struct Foo { int asdf; Foo(int _asdf):asdf(_asdf) {} void frob() {printf("Hi, I am %d\n",asdf);} }; Is there anything worse about the second one? Oh, and by logical extension, here's something that doesn't (AFAIK) work in C++, but does in another language that's syntactically similar: class Foo(int asdf) { void frob() {write("Hi, I am %d\n",asdf);} } Now that's brevity. Why bother saying what's patently obvious? (Pike's "class" keyword is like C++'s "struct", members are public by default.) ChrisA