Naming higher order functions

Steve Holden sholden at holdenweb.com
Thu Jan 31 12:00:27 EST 2002


"Erno Kuusela" <erno-news at erno.iki.fi> wrote in message
news:kuelk63747.fsf at lasipalatsi.fi...
> hello,
>
> what would be a good name for the following function?
>
> def name_me(n):
>     def g(x):
>         return x[n]
>     return g
>
> "make_nth_getter" came to mind but it doesn't sound that good to me.
>
Why not just "nth", or maybe "getitem()" or "getnumber()"?

The really important thing is the names you bind to the functions it
returns, not the name you give the factory. Yeah, what about
"getterfactory()"? I could go on for ever without shedding further light
:^). Here's what I mean:

sixth = nth(6)
item6 = sixth(item)
this6= sixth(this)

or

eighth = getitem(8)
item8 = eighth(item)
that8 = eighth(that)

or

tenth = getnumber(10)
item10 = tenth(item)
theother10 = tenth(theother)

However:

banana = nth(42)
item42 = banana(item)
whatever42 = banana(whatever)

doesn't have quite the same mnemonic ring to it.

whats-in-a-name-ly y'rs  - steve
--
Consulting, training, speaking: http://www.holdenweb.com/
Python Web Programming: http://pydish.holdenweb.com/pwp/








More information about the Python-list mailing list