Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!goblin3!goblin2!goblin.stu.neva.ru!newsfeed1.swip.net!uio.no!news.tele.dk!news.tele.dk!small.news.tele.dk!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.009 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'broken': 0.04; 'that?': 0.05; '*not*': 0.07; '21,': 0.07; 'lines,': 0.07; 'similar,': 0.09; 'cc:addr:python-list': 0.11; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'hint': 0.16; 'ought': 0.16; 'reasonably': 0.16; 'roy': 0.16; 'two,': 0.16; 'subject:python': 0.16; 'applies': 0.16; ':-)': 0.16; 'wrote:': 0.18; 'pieces': 0.19; 'cc:addr:python.org': 0.22; 'cc:2**0': 0.24; 'header:In- Reply-To:1': 0.27; "doesn't": 0.30; 'message-id:@mail.gmail.com': 0.30; 'code': 0.31; 'usually': 0.31; "d'aprano": 0.31; 'steven': 0.31; 'fri,': 0.33; 'third': 0.33; 'maybe': 0.34; 'but': 0.35; 'received:google.com': 0.35; 'in.': 0.36; 'similar': 0.36; 'should': 0.36; 'two': 0.37; 'sometimes': 0.38; 'pm,': 0.38; 'rather': 0.38; 'anything': 0.39; 'explain': 0.39; 'how': 0.40; 'here:': 0.62; 'times': 0.62; 'places': 0.64; 'become': 0.64; 'different': 0.65; 'mar': 0.68; '2-3': 0.68; 'smith': 0.68; 'obvious': 0.74; 'article': 0.77; 'absolutely': 0.87; 'to:none': 0.92 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=gKS4bVrSXuJQIxNATij6RGhRmTo0p6Nvf+/01ltzI3o=; b=p2iFK5ynya2UJHb+LmI7pDf7FqPLN4/sIRHUEOeeQ7F0ipX5Gw7lPeNwXbm/sJuF+y VxCntm/qGnmpd8RgJnfyl2IY3o9UhUjl10SuYzy64PCzoUwuXA1BPzjc707wNb7P9gRd aIRN6CEkOxgq7/HMKS3i37cahkVvOu1ouw9yIaZ2lofzZ0rJlxmMQ+opSRAvReK1HEsj pTzgi/PR6lXueIT+TlVI3xzrAjPsN7apdz3SpZt33QUHIhsa0gWh7rCEm4eqwmxZhc1A wIQZ2alx4tG/qkya5Wk+atPjbPMHhKls0vZkNnXau+sln1DT0hVyiCGw81WXzX3OcbR6 uJqA== MIME-Version: 1.0 X-Received: by 10.68.201.10 with SMTP id jw10mr50860599pbc.25.1395368309430; Thu, 20 Mar 2014 19:18:29 -0700 (PDT) In-Reply-To: References: <87ob10nbeh.fsf@elektro.pacujo.net> <532B4750.2090006@yahoo.com> <87eh1wpr96.fsf@elektro.pacujo.net> <87a9ckpq7y.fsf@elektro.pacujo.net> <87txasoaqi.fsf@elektro.pacujo.net> <532b8f0d$0$29994$c3e8da3$5496439d@news.astraweb.com> Date: Fri, 21 Mar 2014 13:18:29 +1100 Subject: Re: running python 2 vs 3 From: Chris Angelico Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 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: 23 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1395368318 news.xs4all.nl 2908 [2001:888:2000:d::a6]:47330 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:68661 On Fri, Mar 21, 2014 at 12:06 PM, Roy Smith wrote: > In article <532b8f0d$0$29994$c3e8da3$5496439d@news.astraweb.com>, > Steven D'Aprano wrote: > >> The rule of three applies here: anything you do in three different places >> ought to be managed by a function. > > I prefer the rule of two :-) The way I explain it is: Three is a rule of thumb. Sometimes it's blatantly obvious at two, and other times you need four or five similar pieces of code before you can see which part should become the function. If the code's absolutely identical and reasonably long/complex, then yes, two's all you need, but how often is that? Usually it's similar, rather than congruent... err I mean identical. That's where the third usage comes in. Or if it's maybe 2-3 lines, used in two places, it doesn't necessarily need to be a function. Again, a third usage is a strong hint that it should be broken out. The rule doesn't say that anything that *isn't* in three places yet should *not* be broken out. :) ChrisA