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


Groups > comp.lang.python > #19489

Re: Distributing methods of a class across multiple files

From Roy Smith <roy@panix.com>
Newsgroups comp.lang.python
Subject Re: Distributing methods of a class across multiple files
Date 2012-01-26 09:11 -0500
Organization PANIX Public Access Internet and UNIX, NYC
Message-ID <roy-98357C.09110826012012@news.panix.com> (permalink)
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>

Show all headers | View raw


In article <mailman.5080.1327510460.27778.python-list@python.org>,
 Dennis Lee Bieber <wlfraed@ix.netcom.com> wrote:

> 	The old convention I'd learned was to keep functions down to a
> (printer) page (classical 6 lines per inch, 11" high, tractor feed -- so
> about 60 lines per function -- possibly extend to a second page if
> really needed.

The generalization of that is "keep a function small enough that you can 
see it all at once".  In the days of line printers and green-bar, that 
meant about 60 lines.  As we moved to glass ttys, that started to mean 
24 lines.  These days, with most people having large high-res monitors, 
the acceptable limit (by that standard) is growing again.  I can easily 
get 60 lines on my laptop screen.

On the other hand, back in the neolithic age, when line printers and 
mainframes roamed the world, function calls were expensive.  People were 
encouraged to write larger functions to avoid function calls.  Now, 
function calls are cheap.  Both because optimizing compilers and better 
hardware support have made them cheap, and because hardware in general 
has gotten so fast nobody cares about it anymore (nor should they).

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.

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