[Grok-dev] Grokker to remove development code?

Martijn Faassen faassen at startifact.com
Thu Dec 4 08:19:28 EST 2008


Brandon Craig Rhodes wrote:
> Martijn Faassen <faassen at startifact.com> writes:
> 
>> What we *should* do is extend martian so we can tag our classes:
>>
>> class MyView(grok.View):
>>      grok.tag('dev')
> 
> Instead of introducing yet another labelling axis, could marker
> interfaces be used instead?
> 
>  class MyView(grok.View):
>     grok.implements(IDevelopmentOnly)
> 
>  <grok:grok package="." interface_exclude="IDevelopmentOnly">

Small point: You'd need a dotted name to the interface in the ZCML 
directive.

My main point: I'd be in favor of using interfaces for tagging, as they 
support extension relations and the like.

That said, just looking at grok.implements seems like mixing axes. Is or 
is not IDevelopmentOnly an interface of MyView? With layers we've gone 
for a separate axis - is this wrong? I think it's clearer if this 
information is available separately, as it's used for quite different 
reasons and actually during runtime those tags not included aren't even 
registered in the component architecture, so shouldn't show up (unless 
you use the classes manually).

I'd therefore suggest the following:

class MyView(grok.View):
    grok.tag(IDevelopmentMode)

I think this is better than name based tags for two reasons:

* inheritance is possible for interfaces

* having to import IDevelopmentMode is more cumbersome, but also 
guarantees the interpreter checking that this is indeed a unique, shared 
token.

Since you'd want to indicate IDevelopmentMode on the command line and 
config files, we should consider a similar mechanism to give particular 
development "layers" a name, just like in the skinning mechanism:

class IDevelopmentMode(IMode):
     grok.mode('dev')

# imaginary command line
bin/paster --grok-mode=dev serve

Of course which mode the server is being run in should be available 
during run-time as well. I think this conflicts with the ZCML notation 
above as that would allow the same mode to be "on" and "off" dependent 
on which package you're in. I'm not convinced the ZCML notation is the 
right one in fact.

Cool. Now we need a volunteer to change martian and grok to support this 
stuff. :)

Regards,

Martijn



More information about the Grok-dev mailing list