"helper function" style question
Larry Bates
lbates at swamisoft.com
Mon Jul 12 14:42:29 EDT 2004
I think it is a "personal" style question, but
I like the first example (and use it frequently).
The first method also makes it possible to
use K as a base class object, I'm unsure about
the second method (perhaps one of the class
"gurus" can chime in). I believe that in the
second example, hf() function would only be callable
in m1 method. In first example it is callable from
any method (as self._hf()) and can be called externally
as Kclassinstance._hf() (even though the leading
underline "hides" the method). If a function is
only called from inside of a single method, I question
why you would want a function at all.
HTH,
Larry Bates
Syscon, Inc.
"Robert Ferrell" <ferrell at diablotech.com> wrote in message
news:73b00f0c.0407121008.3175107f at posting.google.com...
> I have a style question. I have a class with a method, m1, which
> needs a helper function, hf. I can put hf inside m1, or I can make it
> another method of the class. The only place hf should ever be invoked
> is from inside m1.
>
> Is either style preferred?
>
> Here are two short examples:
>
> Helper function as method:
>
> class K(object):
> def _hf(self):
> print 'Yo'
> def m1(self):
> self._hf()
> return
>
> Helper function as "private" function inside m1.
>
> class K(object):
> def m1(self):
> def hf():
> print 'Yo'
> hf()
> return
>
> Opinions greatly appreciated.
>
> thanks,
> -robert
More information about the Python-list
mailing list