common practice for creating utility functions?
Scott David Daniels
scott.daniels at acm.org
Mon May 15 15:00:33 EDT 2006
John Salerno wrote:
> ...Is it common ...[and preferred] to create a function that has the sole job of
> calling another function?
>
> Example: ... cryptogram. Right now I have four functions:
>
> convert_quote -- the main function that starts it all
> make_code -- makes and returns the cryptogram
> make_set -- called from make_code, converts the quote into a set so each
> letter gets only one coded letter
> test_sets -- makes sure a letter isn't assigned to itself
>
> So my first question is this: should I make a Cryptogram class for this,
> or are functions fine?
Functions are just fine. I'd use a class if they wanted to share state.
> ... can I do something like this:
> def convert_quote(quote):
> return make_code(quote)
> Or does it not make sense to have a function just call another function?
Obviously you _can_ do that. I wouldn't, however. If (to you) the four
functions above "mean" something different, I'd implement convert_quote
with:
convert_quote = make_code
--
-Scott David Daniels
scott.daniels at acm.org
More information about the Python-list
mailing list