Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed2.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.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'initialize': 0.07; '"if': 0.09; '__init__': 0.09; 'apis': 0.09; 'caller': 0.09; 'if,': 0.09; 'method,': 0.09; 'useless': 0.09; 'be:': 0.16; 'constructor.': 0.16; 'exceptions,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'rule.': 0.16; 'sorts': 0.16; 'symlink': 0.16; "where's": 0.16; 'wrote:': 0.18; 'variable': 0.18; 'equivalent': 0.26; 'pass': 0.26; 'header:In-Reply-To:1': 0.27; "doesn't": 0.30; 'message-id:@mail.gmail.com': 0.30; "d'aprano": 0.31; 'embed': 0.31; 'steven': 0.31; 'fri,': 0.33; 'sense': 0.34; 'objects': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'object,': 0.36; 'method': 0.36; 'useful': 0.36; 'should': 0.36; 'level': 0.37; 'being': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'anything': 0.39; 'to:addr:python.org': 0.39; 'skip:p 20': 0.39; 'how': 0.40; 'even': 0.60; 'simple': 0.61; 'subject:skip:o 10': 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=xPpSs9pbJDgupfoMwEfG5wdNstEoKieDg/6weNMESMg=; b=Gs+5C+CWNvxRv6KXhxULghf6sO0XWc9uANX57WRErz/lrqbLBySvLhLVle44+k28sy +8LOAUU2HPL+BtWNxEJzTVQcsudac3RdBEaFZNxyR9XVuHiBI5cfbqDM4z5R0+NrrhLD BINcAqOzebPVCacRhe0P3WOkiPavvYP7yksgzBYpEAkJXpRIbPwsjlRRBnjRDz7b9dil oj97eCj9UFrsKM0+G0PFljev3bqtgbPKvzre+2WvLUMAph06BC8bt9jHcg/XkbvrNQIq 1pbXv7YsotjF1ei2uUKvxRvdi79zBS8pMtLQJ0nWKiulgdcwoHAx5N1/kcs09pNNT9Gc nNww== MIME-Version: 1.0 X-Received: by 10.52.20.210 with SMTP id p18mr8255416vde.42.1368155283478; Thu, 09 May 2013 20:08:03 -0700 (PDT) In-Reply-To: <518c5bbc$0$29997$c3e8da3$5496439d@news.astraweb.com> 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> Date: Fri, 10 May 2013 13:08:03 +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: 34 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1368155286 news.xs4all.nl 15950 [2001:888:2000:d::a6]:33120 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:45076 On Fri, May 10, 2013 at 12:30 PM, Steven D'Aprano wrote: > I must admit I am astonished at how controversial the opinion "if your > object is useless until you call 'start', you should automatically call > 'start' when the object is created" has turned out to be. I share your astonishment. This is a very simple point: If, after constructing an object, the caller MUST call some method on it prior to the object being of use, then better design is to embed that call directly into the constructor. As always, it has its exceptions, but that doesn't stop it being a useful rule. The Path() equivalent would be: p = Path() p.set_path("/foo/bar") if p.exists(): pass Even if you have a set_path() method, it makes good sense to symlink it to __init__ to avoid this anti-pattern. C level APIs often have these sorts of initialization requirements. fd_set selectme; FD_ZERO(&selectme); This is because declaring a variable in C cannot initialize it. Anything that *has* constructors should be using them to set objects up... that's what they're for. Where's the controversy? ChrisA