Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #19492

Re: Distributing methods of a class across multiple files

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 <rosuav@gmail.com>
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 <roy-98357C.09110826012012@news.panix.com>
References <569a94a3-cd84-449b-b0c1-80348014aac6@i10g2000pbl.googlegroups.com> <mailman.5070.1327492214.27778.python-list@python.org> <7c9ae6dd-c175-4376-be70-633785ed9386@iu7g2000pbc.googlegroups.com> <mailman.5080.1327510460.27778.python-list@python.org> <roy-98357C.09110826012012@news.panix.com>
Date Fri, 27 Jan 2012 01:41:47 +1100
Subject Re: Distributing methods of a class across multiple files
From Chris Angelico <rosuav@gmail.com>
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 <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.5129.1327588911.27778.python-list@python.org> (permalink)
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

Show key headers only | View raw


On Fri, Jan 27, 2012 at 1:11 AM, Roy Smith <roy@panix.com> wrote:
> So, I'd say the driving principle should be that a function should do
> one thing.  Every function should have an elevator talk.  You 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".  If it takes longer than that to explain, then
> 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

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Distributing methods of a class across multiple files lh <lhughes42@gmail.com> - 2012-01-24 19:54 -0800
  Re: Distributing methods of a class across multiple files Roy Smith <roy@panix.com> - 2012-01-24 23:05 -0500
  Re: Distributing methods of a class across multiple files Cameron Simpson <cs@zip.com.au> - 2012-01-25 17:15 +1100
  Re: Distributing methods of a class across multiple files "Frank Millman" <frank@chagford.com> - 2012-01-25 10:26 +0200
  Re: Distributing methods of a class across multiple files Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-01-25 11:10 +0000
  Re: Distributing methods of a class across multiple files Jean-Michel Pichavant <jeanmichel@sequans.com> - 2012-01-25 12:49 +0100
    Re: Distributing methods of a class across multiple files lh <lhughes42@gmail.com> - 2012-01-25 07:19 -0800
      Re: Distributing methods of a class across multiple files Neil Cerutti <neilc@norwich.edu> - 2012-01-25 15:42 +0000
      Re: Distributing methods of a class across multiple files Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2012-01-25 11:53 -0500
        Re: Distributing methods of a class across multiple files Roy Smith <roy@panix.com> - 2012-01-26 09:11 -0500
          Re: Distributing methods of a class across multiple files Chris Angelico <rosuav@gmail.com> - 2012-01-27 01:41 +1100
      Re: Distributing methods of a class across multiple files Chris Angelico <rosuav@gmail.com> - 2012-01-26 20:25 +1100

csiph-web