Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #108748

Re: Design: Idiom for classes and methods that are customizable by the user?

From Michael Selik <michael.selik@gmail.com>
Newsgroups comp.lang.python
Subject Re: Design: Idiom for classes and methods that are customizable by the user?
Date 2016-05-17 18:13 +0000
Message-ID <mailman.65.1463508799.19823.python-list@python.org> (permalink)
References (1 earlier) <mailman.617.1463087060.32212.python-list@python.org> <dplassFelugU1@mid.individual.net> <CAGgTfkPeqybAeqXLq8FHyRSb+d8KLemvxLrk8i3PfbWdwV4rBA@mail.gmail.com> <573B300A.5080502@gmx.de> <CAGgTfkPoPxzarh3uazCW0x6ZPwM1wamVDZm8r5h7++8xJkG5pg@mail.gmail.com>

Show all headers | View raw


On Tue, May 17, 2016 at 11:18 AM Dirk Bächle <tshortik@gmx.de> wrote:

>
> > It's not so great to require
> > that the user must explicitly ``add`` their derived class after defining
> > it. Perhaps that add function could be a decorator?
>
> Our current API doesn't use decorators at all, since it's also aimed at
> people with no (or only some) knowledge of Python.


I think you'll find that users of decorators do not need any special
knowledge. The Flask framework (http://flask.pocoo.org/) is proof of that.


> decorators...would have looked strange to the average user perhaps?
>

Many beginners are willing to mimic your example code without questioning
what that "@" thingy is doing above the function or class.

Compare that with trying to explain to a C++ user that in Python classes
are actually objects and you can pass them to the ``add`` function to
register them... that's going to take a while.

We're now free to add them into the mix for our new Python 2.7.x/3.y
> codebase, but this would probably require an API discussion
> first.
>

An alternative would be creating a TaskmasterMeta metaclass that registers
the Taskmaster subclass when it's defined. I'm a little reluctant to
recommend that one. I find decorators to be more elegant.

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

Design: Idiom for classes and methods that are customizable by the user? Dirk Bächle <tshortik@gmx.de> - 2016-05-12 22:51 +0200
  Re: Design: Idiom for classes and methods that are customizable by the user? Marko Rauhamaa <marko@pacujo.net> - 2016-05-13 01:01 +0300
    Re: Design: Idiom for classes and methods that are customizable by the user? Dirk Bächle <tshortik@gmx.de> - 2016-05-13 00:42 +0200
      Re: Design: Idiom for classes and methods that are customizable by the user? Marko Rauhamaa <marko@pacujo.net> - 2016-05-13 08:53 +0300
  Re: Design: Idiom for classes and methods that are customizable by the   user? Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2016-05-13 18:35 +1200
    Re: Design: Idiom for classes and methods that are customizable by the user? Michael Selik <michael.selik@gmail.com> - 2016-05-13 20:33 +0000
    Re: Design: Idiom for classes and methods that are customizable by the user? Dirk Bächle <tshortik@gmx.de> - 2016-05-17 16:51 +0200
    Re: Design: Idiom for classes and methods that are customizable by the user? Michael Selik <michael.selik@gmail.com> - 2016-05-17 18:13 +0000

csiph-web