[Chicago] Factoring fun with functions in Python

Steve Schwarz steve at agilitynerd.com
Wed Nov 14 16:37:12 CET 2012


On Tue, Nov 13, 2012 at 10:35 PM, Dan Krol <orblivion at gmail.com> wrote:
<snip>only solutions I've come up with are A) making functions small but
not that small, and B) defining functions inside other functions, so that
it's clear what functions are there purely for the benefit of other
functions.

> Any ideas on that front? Isn't there such a thing as splitting functions
> up *too* much?
>
A few thoughts I haven't seen anyone else mention yet:
- small functions are easier to write tests for. Ideally they have a well
defined effect and can be named in a way that makes it possible to "just"
read the code of their callers without having to delve in to each function
to find out what it does.
- functions inside functions are definitely not easier to write tests for.
- I prepend "_" to function names for "helper" functions that are not part
of the "API" exposed by the module and put them in module scope. Sometimes
I'll push them down to the bottom of the module to further de-emphasize
them wrt the module's external API.

Best Regards,
Steve
Blogs: http://agilitynerd.com/  http://tech.agilitynerd.com/
Dog Agility Search: http://googility.com/
Dog Agility Courses: http://agilitycourses.com/
http://www.facebook.com/AgilityNerd
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/chicago/attachments/20121114/45638d04/attachment.html>


More information about the Chicago mailing list