is there any principle when writing python function

Chris Angelico rosuav at gmail.com
Mon Aug 29 21:02:52 CEST 2011


On Tue, Aug 30, 2011 at 4:40 AM, Neil Cerutti <neilc at norwich.edu> wrote:
> Wait... not all Python programmers sing?

I do, and there seems to be more than coincidental overlap between
musos and coders.

> The problem with that scenario is that, in real life, there's
> more than one Cerutti.Neil, and they like to move around. ;)

Yes indeed; which means that your Cerutti module is in a package:

from norwich import Cerutti

It's always possible to make a locally-unique identifier into a more
globally unique one by prepending another tag to it. Alternatively,
you need to be duck-typed: you're the Neil Cerutti who writes code,
and if some other Neil Cerutti is asked to write code, he will throw
an exception. That's probably the easiest way to deal with it - but I
don't know of a way to implement it in a coded way. Maybe all names
actually point to lists of objects, and whenever you try to do
something with a name, the system goes through the elements of the
list until one doesn't fail?

Going back to the original question, the length of function name
required for it to be "meaningful" is, obviously, a variable quantity.
But I think it's still reasonable to use that as a rule of thumb for
dividing functions - if you can sanely name both halves, without
putting the entire code into the function name, then you have a case
for refactoring.

ChrisA



More information about the Python-list mailing list