Distributing methods of a class across multiple files
Roy Smith
roy at panix.com
Thu Jan 26 09:11:11 EST 2012
In article <mailman.5080.1327510460.27778.python-list at python.org>,
Dennis Lee Bieber <wlfraed at 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.
More information about the Python-list
mailing list