On Fri, Jan 27, 2012 at 1:11 AM, Roy Smith <r...@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 -- http://mail.python.org/mailman/listinfo/python-list