Path: csiph.com!usenet.pasdenom.info!news.etla.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed1.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.114 X-Spam-Level: * X-Spam-Evidence: '*H*': 0.77; '*S*': 0.00; 'c++,': 0.07; 'agrees': 0.09; 'constructor': 0.09; 'cc:addr:python-list': 0.11; '(and,': 0.16; 'called.': 0.16; 'kern': 0.16; 'roy': 0.16; 'subclass': 0.16; 'thread,': 0.16; 'throw': 0.16; 'wrote:': 0.18; 'separate': 0.22; 'cc:addr:python.org': 0.22; 'earlier': 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; 'header:In-Reply-To:1': 0.27; 'robert': 0.30; 'then.': 0.30; 'message-id:@mail.gmail.com': 0.30; 'exceptions': 0.31; 'class': 0.32; 'handled': 0.32; 'everyone': 0.33; 'entirely': 0.33; "i'd": 0.34; 'could': 0.34; 'received:209.85': 0.35; 'common': 0.35; 'received:209.85.220': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'c++': 0.36; 'curious': 0.36; 'instances': 0.36; 'method': 0.36; 'should': 0.36; 'virtual': 0.37; 'received:209': 0.37; 'step': 0.37; 'being': 0.38; 'implement': 0.38; 'either': 0.39; 'days': 0.60; 'even': 0.60; 'mentioned': 0.61; 'new': 0.61; 'skip:n 10': 0.64; 'school': 0.64; 'talking': 0.65; 'smith': 0.68; 'article': 0.77; 'doubts': 0.84; 'fail.': 0.84; 'oscar': 0.84; 'subject:skip:o 10': 0.84; 'valid,': 0.84; 'poorly': 0.93; '2013': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:mime-version:in-reply-to:references:from:date:message-id :subject:to:cc:content-type; bh=fgxxPOpxKbY6NuMJ1DFNZ5a0gFSgBMPvBq+31oTJnic=; b=MUaFmxOaIUjGTwnSB/rMZ/mE7QMaJckbwBVA/8uu/xLSnlMWRx9WoQ6N5i52OUphnS zD5Gp6P4ON56u1TKzLw8i6JXlGX6arMpFyzJaqAXuU3BL5eXqNA6FA6zPbqNMG91dOvi 84J+647dE7MgQ3qqi5GvDCwIOH5bltLvvu/lSPIg3No+DFZNHCuGOae3iADt012qxiGV 4PIGQP3Nxi/V+pGNfRz89rL+RDgmTW7Nbt+jswGKhkxx5G6Y+kwa2MjOYnM6JZKzXdpV YLogoNQdKDSA8os5Ady6KxdWQvE2RjbhTT4eUJyUgHhjN67EP4KUjFjHmFpZ3EwxMdQt P9Tg== X-Received: by 10.52.93.78 with SMTP id cs14mr9830601vdb.17.1368196161033; Fri, 10 May 2013 07:29:21 -0700 (PDT) MIME-Version: 1.0 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> From: Oscar Benjamin Date: Fri, 10 May 2013 15:29:00 +0100 Subject: Re: object.enable() anti-pattern To: Roy Smith Content-Type: text/plain; charset=ISO-8859-1 Cc: python-list@python.org 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: 30 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1368196163 news.xs4all.nl 15975 [2001:888:2000:d::a6]:47289 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:45099 On 10 May 2013 15:01, Roy Smith wrote: > In article , > Robert Kern wrote: > >> I'd be curious to see in-the-wild instances of the anti-pattern that >> you are talking about, then. I think everyone agrees that entirely >> unmotivated "enable" methods should be avoided, but I have my doubts >> that they come up very often. > > As I mentioned earlier in this thread, this was a common pattern in the > early days of C++, when exceptions were a new concept and handled poorly > by many compilers (and, for that matter, programmers). > > There was a school of thought that constructors should never be able to > fail (because the only way for a constructor to fail is to throw an > exception). The pattern was to always have the constructor succeed, and > then either have a way to check to see if the newly-constructed object > was valid, or have a separate post-construction initialization step > which could fail. It's not just because of exceptions. In C++ virtual method calls in a constructor for a class A will always call the methods of class A even if the object being constructed is actually of a subclass B because the B part of the object isn't initialised when the A constructor is called. There may be a better way to do this since I last used C++ but as I remember it the two-phase pattern was a recommended way to implement polymorphic behaviour during initialisation. Oscar