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.007 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'languages,': 0.04; 'patterns': 0.04; 'true,': 0.05; 'applicable,': 0.07; 'c++,': 0.07; 'agrees': 0.09; 'assumed': 0.09; 'constructor': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'specific.': 0.09; 'statements': 0.09; 'assume': 0.14; 'suggest': 0.14; '"can\'t': 0.16; '(and,': 0.16; 'enough.': 0.16; 'kern': 0.16; 'most)': 0.16; 'possibly,': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'roy': 0.16; 'rule.': 0.16; 'thread,': 0.16; 'throw': 0.16; 'trivially': 0.16; 'underlying': 0.16; 'appropriate': 0.16; 'wrote:': 0.18; 'later': 0.20; 'meant': 0.20; 'separate': 0.22; 'header:User-Agent:1': 0.23; 'case.': 0.24; 'interpret': 0.24; 'earlier': 0.24; 'header:X-Complaints- To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'robert': 0.30; 'see,': 0.30; 'then.': 0.30; 'bunch': 0.31; 'exceptions': 0.31; 'proposing': 0.31; 'steven': 0.31; 'universal': 0.31; 'class': 0.32; 'handled': 0.32; 'quite': 0.32; 'everyone': 0.33; 'entirely': 0.33; "i'd": 0.34; 'could': 0.34; 'message.': 0.35; 'agree': 0.35; 'common': 0.35; 'something': 0.35; 'point.': 0.35; 'but': 0.35; 'there': 0.35; 'really': 0.36; 'c++': 0.36; 'curious': 0.36; 'instances': 0.36; 'like,': 0.36; 'real-time': 0.36; 'reality': 0.36; 'doing': 0.36; 'useful': 0.36; 'should': 0.36; 'example,': 0.37; 'step': 0.37; 'being': 0.38; 'to:addr :python-list': 0.38; 'rather': 0.38; 'bad': 0.39; 'embedded': 0.39; 'to:addr:python.org': 0.39; 'either': 0.39; 'received:org': 0.40; 'days': 0.60; 'even': 0.60; 'read': 0.60; 'continued': 0.60; 'mentioned': 0.61; 'new': 0.61; 'today,': 0.61; 'strictly': 0.61; 'skip:n 10': 0.64; 'our': 0.64; 'more': 0.64; 'school': 0.64; 'talking': 0.65; 'world': 0.66; 'biggest': 0.67; 'believe': 0.68; 'book.': 0.68; 'smith': 0.68; 'url:tinyurl': 0.69; 'article': 0.77; 'doubts': 0.84; 'eco': 0.84; 'fail.': 0.84; 'sacrificing': 0.84; 'subject:skip:o 10': 0.84; 'terrible': 0.84; 'universally': 0.84; 'valid,': 0.84; 'poorly': 0.93; 'reducing': 0.93 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Robert Kern Subject: Re: object.enable() anti-pattern Date: Fri, 10 May 2013 16:33:09 +0100 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> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: 213.1.240.226 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:17.0) Gecko/20130328 Thunderbird/17.0.5 In-Reply-To: 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: 64 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1368200002 news.xs4all.nl 15987 [2001:888:2000:d::a6]:60548 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:45110 On 2013-05-10 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. > > See, for example, the isValid() and Exists() calls for RogueWave's > RWFile class (http://tinyurl.com/c8kv26g). And also, > http://tinyurl.com/cgs6clx. > > Even today, there are C++ implementations which do not use exceptions. > Some are for use in embedded or real-time systems where things need to > be strictly time-bound and/or memory-bound. Others are for historical > reasons (http://tinyurl.com/6hn4zo). > > Once people were used to writing "can't fail" constructors in C++, they > often continued using that pattern in other languages, where the > underlying reasons no longer made sense. Quite possibly, they never > even knew the underlying reasons; they were taught, "Constructors must > never fail", and assumed it was a universal rule. Right, this is one of the "bad reasons" I talk about later in my message. The authors had a reason in their mind for doing it (they thought it was a universal rule); it was just a bad one. It's more useful to talk about why people thought they should follow that pattern than to just say "there is no reason to do this". > This, BTW, is one of my biggest beefs with the classic Gang Of Four > pattern book. It presents a bunch of patterns as being universally > applicable, when in reality many (if not most) of them are highly C++ > specific. > > BTW, whenever I read things like, "I think everyone agrees", I > automatically assume what the writer really meant was, "I, and all the > people who agree with me, think". Hah! Fair enough. I actually meant it to emphasize that I thought that Steven was overly reducing his statements to something that was trivially true, sacrificing content for validity. I will suggest that your interpretation of that phrase is more appropriate when the speaker is proposing something of their own rather than (partially) conceding a point. The exaggeration is only self-aggrandizing in the former case. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco