Path: csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed4.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.005 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; '"""': 0.07; 'apis': 0.09; 'attributes': 0.09; 'deprecated': 0.09; 'exec': 0.09; 'indication': 0.09; 'modifies': 0.09; 'undefined': 0.09; 'gui': 0.12; 'systems.': 0.12; 'called,': 0.16; 'deprecation': 0.16; 'descriptors,': 0.16; 'exists,': 0.16; 'fork': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'hrm.': 0.16; 'kern': 0.16; 'most)': 0.16; 'processes.': 0.16; 'sat,': 0.16; 'wrote:': 0.18; 'variable': 0.18; 'meant': 0.20; 'example': 0.22; 'either.': 0.24; 'example.': 0.24; 'frameworks': 0.24; 'merge': 0.24; '(or': 0.24; "i've": 0.25; 'pass': 0.26; 'values': 0.27; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'am,': 0.29; 'robert': 0.30; 'then.': 0.30; 'message- id:@mail.gmail.com': 0.30; 'code': 0.31; 'though.': 0.31; 'file': 0.32; 'regular': 0.32; 'another': 0.32; 'running': 0.33; 'not.': 0.33; 'skip:b 30': 0.33; 'actual': 0.34; 'there,': 0.34; "i'd": 0.34; 'could': 0.34; 'created': 0.35; 'except': 0.35; 'etc': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'really': 0.36; 'curious': 0.36; 'functions.': 0.36; 'instances': 0.36; 'done': 0.36; 'useful': 0.36; 'possible': 0.36; 'similar': 0.36; 'two': 0.37; 'button': 0.38; '8bit%:86': 0.38; 'mapping': 0.38; 'to:addr:python-list': 0.38; '(from': 0.39; 'to:addr:python.org': 0.39; 'either': 0.39; 'liked': 0.60; "you're": 0.61; 'talking': 0.65; 'effectively': 0.66; 'family': 0.73; 'behavior': 0.77; 'forks': 0.84; 'lightweight': 0.84; 'limits,': 0.84; 'placement': 0.84; 'subject:skip:o 10': 0.84; 'favour': 0.91; '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:content-transfer-encoding; bh=Ia541koALX6SMoDaUquycO556xd7DGX3DpbNa+6nhbY=; b=NMofkTLHqS//Uf8mUCEHtVJPzvdg/x7IMuL/nO3kLrKsaFppC14fA4y6ffdOXf7KZh wl7RcI61iDqE1YPjGxTG1Pa9szJL2wk8zI0nVkAdHJxzaGzWoZazC9BjL+GDBw7sKnGm TeT6G63vAg97Dr/lZ/HHnPOpP0JQ3dzVo9Q3alIM7vggjAjIanC2KTTKFojNDFFt3C3z qDnDze02i7RLSR3LpZHdedlwO1A96UNsMC3quuozVGJQNFm0SzuNnn1ZjrUl0l4VIrVr 919UZh4BfBlfxNp07BeohId0u+Tr0Q4S73XX7yOcdhQMTw6TWU/nMRhG3sET84P5VXYV xcbw== MIME-Version: 1.0 X-Received: by 10.58.56.161 with SMTP id b1mr11887278veq.42.1368206700080; Fri, 10 May 2013 10:25:00 -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 03:24:59 +1000 Subject: Re: object.enable() anti-pattern From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable 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: 61 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1368206709 news.xs4all.nl 15944 [2001:888:2000:d::a6]:56669 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:45118 On Sat, May 11, 2013 at 1:44 AM, Serhiy Storchaka wro= te: > 10.05.13 15:19, Robert Kern =D0=BD=D0=B0=D0=BF=D0=B8=D1=81=D0=B0=D0=B2(= =D0=BB=D0=B0): > >> I'd be curious to see in-the-wild instances of the anti-pattern that you >> are talking about, then. > > > Many (if not most) GUI frameworks use this pattern. > > button =3D Button("text") > button.setForegroundColor(...) > button.setBackgoundColor(...) > button.setFont(...) > button.setRelief(...) > button.setBorder(...) > button.setWidth(...) > button.setAction(...) > button.setMouseListener(...) > button.place(...) The button really exists, though. You could merge the creation and placement (or in the case of a window/dialog, the creation and showing), but it's often useful to not. However, in the specific case you have there, there's an alternative: a mapping of attributes and values passed to the constructor, and then you could pass the constructed object directly to a place(). That would let you, if you wished, effectively construct a Button with a parent right there, which makes reasonable sense. > Another example is running a subprocess in Unix-like systems. > > fork() > open/close file descriptors, set limits, etc > exec*() Hrm. Not really a corresponding example. After you fork, you have two actual processes. Following up with an exec is only one of the possible options; I've done code that forks and execs, and code that forks and keeps running, and neither of them feels "wrong" in any way. There IS a function that's similar to what you're saying, and that's vfork: """ (From POSIX.1) The vfork() function has the same effect as fork(2), except that the behavior is undefined if the process created by vfork() either modifies any data other than a variable of type pid_t used to store the return value from vfork(), or returns from the function in which vfork() was called, or calls any other function before successfully calling _exit(2) or one of the exec(3) family of functions. """ It's deprecated because it's so fragile (and because regular fork() isn't that much less efficient now; AIUI, vfork was meant to be a lightweight fork). I would say that the deprecation of vfork in favour of fork is a strong indication that the object.enable() anti-pattern can come up in kernel APIs too, and isn't liked there either. ChrisA