Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!newsfeed.xs4all.nl!newsfeed5.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.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python,': 0.01; 'instance,': 0.05; 'c++,': 0.07; 'subject:files': 0.09; 'am,': 0.12; 'received:209.85.210.174': 0.13; 'received:mail- iy0-f174.google.com': 0.13; 'agreed,': 0.16; 'elevator': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'roy': 0.16; 'true),': 0.16; '\xa0you': 0.16; 'wrote:': 0.16; 'jan': 0.19; 'holds': 0.21; 'header:In-Reply-To:1': 0.22; '\xa0if': 0.23; 'code': 0.25; '(in': 0.26; 'function': 0.27; 'message- id:@mail.gmail.com': 0.28; '27,': 0.28; 'fri,': 0.30; 'handling': 0.30; 'separated': 0.30; 'quite': 0.31; 'yet': 0.32; 'requests': 0.32; 'to:addr:python-list': 0.33; 'rule': 0.34; 'probably': 0.35; 'but': 0.37; "there's": 0.37; 'received:google.com': 0.37; 'some': 0.38; 'received:209.85': 0.38; 'several': 0.38; 'should': 0.38; "i'd": 0.39; 'received:209': 0.39; 'subject:: ': 0.39; 'to:addr:python.org': 0.40; 'type': 0.60; 'perfect': 0.64; '"sorry,': 0.84; 'talk,': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; bh=DQlMJTrXp0u0uuVy7iWw4NUdUa56sleL8HILbtfBZiE=; b=L1+zZtjc0EURHotFzggD1x6EopR2fz8rC0AJtP+Tuq8bQJTJ2/lkx5JJY0PVDSE4xh 0kv9m7IgOPRlgANInr4Qp6Yqg5UFsTI/myb3EJEdo+Mdw8pH95sr25z1TerQ4LsMM6tB uqyUE/6/T/RdeH7Co6SumtL5lqA4Aik8g01Hw= MIME-Version: 1.0 In-Reply-To: References: <569a94a3-cd84-449b-b0c1-80348014aac6@i10g2000pbl.googlegroups.com> <7c9ae6dd-c175-4376-be70-633785ed9386@iu7g2000pbc.googlegroups.com> Date: Fri, 27 Jan 2012 01:41:47 +1100 Subject: Re: Distributing methods of a class across multiple files From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 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: 22 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1327588911 news.xs4all.nl 6916 [2001:888:2000:d::a6]:44685 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:19492 On Fri, Jan 27, 2012 at 1:11 AM, Roy Smith wrote: > So, I'd say the driving principle should be that a function should do > one thing. =A0Every function should have an elevator talk. =A0You should = be > able to get on an elevator with a function and when you ask it, "So, > what do you do?", it should be able to explain itself before you get to, > "Sorry, that's my floor". =A0If it takes longer than that to explain, the= n > it's probably several functions fighting to get out. Agreed, that's definitely a good rule of thumb. But there's still some value in keeping the code length down too. In a program I maintain at work (in C++, but the same holds true), some functions have a perfect elevator talk, yet are quite a few screenfuls of code - this is not really advisable. For instance, one function is "handle responses to previously-sent requests". It incorporates all the code for handling requests of type X, of type Y, and of type Z. If I were writing this from scratch in Python, I would probably have X, Y, and Z all separated out, and the checkresponses function would simply be a dispatcher. ChrisA