Python vs PHP

Valentino Volonghi aka Dialtone dialtone.##NOSPAM#$#$$# at gmail.com
Sat Oct 23 02:19:57 CEST 2004


Ian Bicking <ianb at colorstudy.com> wrote:
> The question then is, what are you trying to achieve with nevow's 
> templating?  (Or maybe, what do you think is achieved?)  I don't think 

Cleaner templates, and sometimes to avoid disk templates at all (when they
are not needed). Nevow template is also wonderful in giving the programmer
the ability to modify and transform the DOM at will (almost).

> anyone is achieving the separation of rendering logic from control or 
> business logic with templating -- rendering logic is too sophisticated 
> (in real applications) to always rely on a template.  In ZPT, some logic 
> remains in the template; the amount of logic is flexible, and frequently 
> changes back and forth as the application is developed.

Why can't you put rendering logic in a python file and the template only in
the template? just allow me to modify the DOM Tree as I need to while I'm
rendering, then the final output will be what you expected. This is what
Nevow does.

> Nevow has a very strong limit to how much logic can go in the page -- 
> and that limit is very low.  It's not a limit of zero, since it is more 
> sophisticated than something like XMLC or the DOM.  But it's not 
> terribly high.

Nevow _CAN_ embed code in the template. and you can do that in this way:

<n:invisible n:render="python x=2**4" />

with this code in the python file:

    def render_python(self, arg):
        def _(self, ctx, data):
            exec arg
            return ctx.tag[x]
        return _

I would also say that Nevow templating has all the very same features you
can find in ZPT. You just have to code them yourself, if you really really
need to.

But Nevow is cleaner than ZPT, because there is no actual reason to embed
python code in the template. If you really really need to transform the DOM
in some way you can do that from the python side.

Actually, you can do everything from the python side if you want.

> is usually the case), I'm not a bottleneck.  I'm not sure this is 
> possible in Nevow.

It is as I wrote above. Nevow templating system is _extremely_ flexible and
can be made to do almost everything you need to.

> the template.  To a degree that's already true.  OTOH, I don't know if 
> it's helpful to code alternating row colors for a table in Python, when 
> it will be necessarily far away from the table that needs the coloring.

It is not a necessity. You can code that directly in the template:

<table nevow:data="some_data" nevow:render="sequence">
   <tr nevow:pattern="item" class="odd">...</tr>
   <tr nevow:pattern="item" class="even">...</tr>
</table>

Will work, as expected and will build an alternating color table, I can't
see how this is hard to understand for a designer or any not experienced
programmer.

> Anyway, I'm very suspicious of any system which limits the programmer 
> for their own good.

Which, I would say, It clearly not Nevow.

Sry If I misunderstood something, I'm not that keen with english so... :)

-- 
Valentino Volonghi aka Dialtone
Now running FreeBSD 5.3-beta7
Blog: http://vvolonghi.blogspot.com




More information about the Python-list mailing list