alias method definitions / syntactic sugar suggestion

Tennessee Leeuwenburg tleeuwenburg at gmail.com
Thu Mar 5 23:45:31 EST 2009


On Fri, Mar 6, 2009 at 3:39 PM, Chris Rebert <clp2 at rebertia.com> wrote:

> On Thu, Mar 5, 2009 at 6:17 PM, Tennessee Leeuwenburg
> <tleeuwenburg at gmail.com> wrote:
> > I'm not sure if this problem I face affects many other people, but I'll
> just
> > describe it and see what kind of feedback I get.
> >
> > I have a suggestion for a new piece of Python syntax when defining
> methods.
> > I have seen the following done, and have done it myself
> >
> >
> > class FanstasticClass:
> >
> >     def __init__(self):
> >         self.someFantasticMethod("Hello")
> >
> >     def someFantasticMethod(self, argument = True):
> >         print argument
> >
> >     justAsFantastic = someFantasticMethod
>
> This sounds like a code smell to me. You shouldn't have 2 methods with
> different names that do the same thing, it seems like bad design IMHO.
> Also, I don't think this is done anywhere near frequently enough to
> warrant new syntax. I'm -1 on the idea personally.


Yeah, I can see that. There is one instance where I've done it personally,
and another where I've seen it done.

Where I've done it personally, it was to, shall we say, compensate for a
design feature. Where I've seen it done was (I think) for
backwards-compatibility reasons.

*If* you are going to have two methods with different names that do the same
thing, they *really should* execute the same lines of code! :)

The alternative of course is:
   def justAsFantastic(self):
      return self.someFantasticMethod()


In fact, probably I should just do that... at the time it seemed appropriate
to do the alias thing.

-T
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20090306/02a9edd4/attachment.html>


More information about the Python-list mailing list