common practice for creating utility functions?

Dan Sommers me at privacy.net
Mon May 15 20:52:45 CEST 2006


On Mon, 15 May 2006 18:26:01 GMT,
John Salerno <johnjsal at NOSPAMgmail.com> wrote:

> So my first question is this: should I make a Cryptogram class for
> this, or are functions fine? ...

Perhaps I'm "old school," but I don't bother with classes unless I'm
going to end up with multiple instances (or I'm pushed into a corner by,
e.g., a GUI framework).

> ... If the latter, then back to my original point:  can I do something
> like this:

> def convert_quote(quote):
>     return make_code(quote)

Of course you can.  Or, since this is python, you can also do this:

    convert_quote = make_quote

> Or does it not make sense to have a function just call another
> function?

If there's a good design-level reason (like keeping certain objects or
classes unaware of others, or leaving room for something you know you
will add later), then there's nothing wrong with a function consisting
solely of another function call.  If you end up with a lot of those tiny
functions, though, and they persist through multiple development cycles,
then you may be making a systematic mistake in your design.

Regards,
Dan

-- 
Dan Sommers
<http://www.tombstonezero.net/dan/>
"I wish people would die in alphabetical order." -- My wife, the genealogist



More information about the Python-list mailing list