Is this a case for metaclasses?

Discussion in 'Python' started by Hartmut Goebel, Aug 5, 2004.

  1. Hi,

    I'm currently implementing a tool for auto-generating webforms from a
    desription file. The output should become a php-script, an asp-script,
    zope-formulator or such. Each if it may (or may not) have javascript
    additions. The output format should be defined ar runtime (php,
    php+javascrip, asp, asp+javascript, etc.).

    Currently I have a fixed class hierarchy:

    generic : implements generic html widgets (input, radiobuttons)
    php : "mixin" for adding php-specifi code to the widget,
    eg. getting values from HTTP_POST_VARS/_POST
    javascript : adds javascript scripts, eg. error checking

    Obviously this does not scale as soon as I add more mid-layers (asp,
    psp, etc.).

    For me this sounds like I could benefit from using metaclasses here.
    Before I start implementing such a beast, I want to be shure, there will
    be a benefit.

    Any suggestions?

    Schönen Gruß - Regards
    Hartmut Goebel

    | Hartmut Goebel | IT-Security -- effizient |
    | | |
    Hartmut Goebel, Aug 5, 2004
    1. Advertisements

  2. Metaclasses are essentially syntactic sugar. You can do more or less
    everything without them. For instance you can use a poor man function
    format your classes as you wish. Then, you have to apply the function
    to the every subclass by hand. If you use a metaclass, subclasses are
    automatically reformatted, instead. So, using a function means
    a bit more typing but greater expliciteness. Metaclasses are okay
    if you want to hide to your users the fact that something magic is
    going on.

    Michele Simionato
    Michele Simionato, Aug 5, 2004
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.