Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!rt.uk.eu.org!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.020 X-Spam-Evidence: '*H*': 0.96; '*S*': 0.00; 'patterns': 0.04; 'explicit': 0.07; 'agrees': 0.09; 'method,': 0.09; 'method:': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'constructor.': 0.16; 'fine.': 0.16; 'forbids': 0.16; 'kern': 0.16; 'naming': 0.16; 'programmers.': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'specific,': 0.16; 'underlying': 0.16; 'all.': 0.16; 'wrote:': 0.18; 'discussion': 0.18; 'bit': 0.19; 'file,': 0.19; 'not,': 0.20; 'separate': 0.22; 'header:User- Agent:1': 0.23; 'instead.': 0.24; 'interpret': 0.24; 'file.': 0.24; "i've": 0.25; 'permission': 0.26; 'pass': 0.26; 'least': 0.26; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'idea': 0.28; 'point': 0.28; 'moved': 0.30; 'robert': 0.30; 'said,': 0.30; 'then.': 0.30; "i'm": 0.30; 'about.': 0.31; "d'aprano": 0.31; 'object.': 0.31; 'steven': 0.31; 'another': 0.32; 'open': 0.33; 'everyone': 0.33; 'entirely': 0.33; 'programmers': 0.33; 'sense': 0.34; "i'd": 0.34; 'but': 0.35; 'there': 0.35; 'curious': 0.36; 'done,': 0.36; 'instances': 0.36; 'object,': 0.36; 'done': 0.36; 'useful': 0.36; 'should': 0.36; 'experience,': 0.37; 'wrong': 0.37; 'others.': 0.38; 'security,': 0.38; 'to:addr:python-list': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'either': 0.39; 'skip:p 20': 0.39; 'received:org': 0.40; 'most': 0.60; 'first': 0.61; 'discuss': 0.62; "you've": 0.63; 'show': 0.63; 'our': 0.64; 'more': 0.64; 'talking': 0.65; 'world': 0.66; 'believe': 0.68; 'natural': 0.68; 'design.': 0.68; 'limit': 0.70; 'continuum': 0.84; 'doubts': 0.84; 'eco': 0.84; 'entity,': 0.84; 'rubbish': 0.84; 'subject:skip:o 10': 0.84; 'terrible': 0.84; 'novice': 0.91; 'reasons,': 0.91; 'story.': 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 13:19:05 +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: <518cd360$0$29997$c3e8da3$5496439d@news.astraweb.com> 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: 49 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1368188358 news.xs4all.nl 16003 [2001:888:2000:d::a6]:57746 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:45093 On 2013-05-10 12:00, Steven D'Aprano wrote: > But either way, that's fine. You've found an object where it does make > sense to have an explicit "make it go" method: first one entity has > permission to construct the object, but not to open the underlying file. > Another entity has permission to open the underlying file, but not to > create the object. I have no idea whether this is a reasonable security > design or not, it actually sounds a bit rubbish to me but what do I know? > So let's treat it as a reasonable design. > > As I've said, repeatedly, that's not what I'm talking about. > > When you DON'T have useful things that can be done with the object before > calling "enable", then it is an anti-pattern to require a separate call > to "enable" method, and the enable functionality should be moved into the > object constructor. If you DO have useful things that can be done, like > pass the object to another entity, for security, then that's a whole > 'nuther story. 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. Do programmers have a natural tendency to make an extra, completely unnecessary method? I would think that they have a natural tendency to the opposite. In my experience, everyone has a reason in mind when they follow a pattern/anti-pattern. It is pretty rare that someone just does some specific, nameable thing for no reason at all. There is no need to call out an anti-pattern for which no one has a reason to do it. But there is a continuum of reasons. Some reasons are better than others. Some reasons only apply in a small set of circumstances but seem like they would apply more generally, at least to novice programmers. Programmers can be wrong about what they think the (anti-)pattern actually achieves. The whole point of naming an anti-pattern is to discuss those reasons, show where they are misapplied, where YAGNI, why novices overuse it, other patterns that should be used instead, and also the circumstances where it is actually a good pattern instead. To artificially limit the discussion of the anti-pattern to the trivial, entirely unmotivated case forbids most of the interesting and instructive parts of the conversation. -- 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