[Twisted-web] Re: Good ROM tool ?

Valentino Volonghi aka Dialtone dialtone at divmod.com
Wed Jan 18 10:40:08 MST 2006

On Wed, Jan 18, 2006 at 05:25:38PM +0100, Andrea Arcangeli wrote:

> 	def render_book_composite(self, ctx, data):
> 		ptrn_bid = inevow.IQ(ctx).patternGenerator('book_sequence_bid')
> 		ptrn_ask = inevow.IQ(ctx).patternGenerator('book_sequence_ask')
> 		return ctx.tag[[ tags.tr(_class="book_outside")
> 				 [tags.td(_class="book_outside")[ptrn_bid(data=(x[0], x[1], x[2]))],
> 				  tags.td(_class="book_outside")[ptrn_ask(data=(x[0], x[3], x[4]))]]
> 				 for x in data ]]
> 	def render_book_sequence(self, ctx, data): 
> 		'This is the same as "sequence" but uses data[1] instead of data'
> 		tag = ctx.tag
> 		headers = tag.allPatterns('header')
> 		pattern = tag.patternGenerator('item')
> 		divider = tag.patternGenerator('divider', default=tags.invisible)
> 		content = [(pattern(data=element), divider(data=element)) for element in data[2]]
> 		if not content:
> 			content = tag.allPatterns('empty')
> 		else:
> 			## No divider after the last thing.
> 			content[-1] = content[-1][0]
> 		footers = tag.allPatterns('footer')
> 		return tag.clear()[ headers, content, footers ]
> 	def render_book_header(self, ctx, data):
> 		currency = data[0]
> 		nr_orders = data[1]
> 		ctx.fillSlots('currency', currency)
> 		nr_orders_str = '%d Order' % nr_orders
> 		if nr_orders != 1:
> 			nr_orders_str += 's'
> 		if nr_orders > BOOK_SIZE:
> 			nr_orders_str += ' (%d not shown)' % (nr_orders-BOOK_SIZE)
> 		ctx.fillSlots('nr_orders', nr_orders_str)
> 		return ctx.tag
> If you find the above readable after 1 day, then it means you've a very
> good memory and you only work on Nevow, I work on a moltitude of
> different projects so there's no way I can know exactly what the
> patternGenerator does or other subtle details with allPatterns,
> inevow.IQ etc...  Plus the code renders slow (no surprise given all
> those inevow.* and tags.pattern*).

I agree the code above is ugly, today I wouldn't write it that way of course.
Since I don't remember your constraints I can't comment too much on the code
above. Besides one thing:

I've been rather dumb with the code above to be honest.

data[2] can be done pretty easily with:

<tr nevow:pattern="item">
    <td nevow:data="2" nevow:render="blabla" />

One thing that I remember though was the constraint on having a renderer to
generate the book_header because you didn't want to repeat the html for the 3
currencies (something that any designer would do to style the page in the
right way). There is a much better way to deal with that problem and it's the
way you used below for cheetah:

<table nevow:data="currencies">
    <tr nevow:render="sequence">
        <td nevow:pattern="item">
            <table nevow:render="sequence">
                <tr nevow:pattern="item">
                    <td nevow:data="0" nevow:render="data" />
                    <td nevow:data="1" nevow:render="data" />
                    <td nevow:data="2" nevow:render="data" />

> As soon as I rewrite the whole thing with Cheetah it'll be like this!!
> #for $currency in $currencies
> 	<table>
> #for $entry in $currency
> 		<table>
> [..]
> 		<td>$entry.something</td>
> [..]
> 		</table>
> #end for
> 	</table>
> #end for

> It's obvious what is an order of magnitude more readable... There's no
> chance I may not be able to understand the above, with Cheetah one
> doesn't need to be a nevow hacker to render two nested tables.

As I showed the code here is translated with the simple yet more flexible
template above. With a bit more work (like returning a dictionary from the
query instead of a list) it could become:

<table nevow:data="currencies">
    <tr nevow:render="sequence">
        <td nevow:pattern="item">
            <table nevow:render="sequence">
                <tr nevow:pattern="item" nevow:render="mapping">
                    <td><nevow:slot name="first_column" /></td>
                    <td><nevow:slot name="second_column" /></td>
                    <td><nevow:slot name="third_column" /></td>
                    <td><nevow:slot name="fourth_column" /></td>
                    <td><nevow:slot name="fifth_column" /></td>

Which would be even faster thanks to using only one render instead of 4/5
(which means only 1 python function call, which is what is slow).

> As said yesterday it's a breath of fresh air being able to get full
> flexibility with full python control mixed with html, without having to
> call into obscure things like nevow.IQ. If you prefer the nevow version
> of rendering nested tables, I think you must be a nevow developer, no
> mere mortal out there could ever prefer the nevow version if compared to
> the Cheetah version.

The nevow way of rendering nested tables is the one above. The one I gave you
a year ago does something wrong (or it does that in face of some kind of

And yes, Nevow is not perfect. Now you are starting insulting the others' work
just because you haven't been able to understand it at all. We are friends and
I don't think my work (but not only mine) deserves such a bad judgement. First
of all if you think you can do better then do it, and after if you don't like
Nevow then fine, but your recent rants seem to grow from something else than
technical problems. See? That's exactly why after some point, and I speak for
myself, I stop caring for users. This is something that happens to me daily
with both twisted and Nevow and others, I don't have the time to care for all
the users complaining because they want X or Y and/or because they don't like
Z. Nobody is paying me to work for them on what they want, I have a job,
university to finish and some free time that I want to preserve. If you
disagree then step in or pay some of us to work on
twisted/nevow/something_else otherwise then you should have made some
library/framework evaluation before starting with your life's project and you
can't blame anyone because you made that evaluation wrong even if you are now

> Also note, I'm recompiling the templates every time, the same way nevow
> parses xml every time. There's also the option to precompile them to get
> even high perf, but since I can't measure any slowdown in the rendering
> anymore (it's already a lot faster than nevow), there's no point for me
> to precompile the templates right now.

And now we start with FUD. Just to show you don't actually understand nevow
you are saying something plain false. Nevow never recompiles templates unless
you modify them. It parses and precompiles templates once.

> On the long term techning Cheetah how to handle a deferred would be
> cool.

And impossible if Cheetah is not extremely well designed (by impossible I mean
more work than outcome is worth).

Now to put an end to this: I don't think I'll have the time to keep answering
in this thread, both because I've lost any interest in this thread and because
It's clear that you simply don't like Nevow which is fine, but I beg you not
to spread any more FUD.

Valentino Volonghi aka Dialtone
Now Running MacOSX 10.4
Blog: http://vvolonghi.blogspot.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 186 bytes
Desc: not available
Url : http://twistedmatrix.com/pipermail/twisted-web/attachments/20060118/d5d8cefc/attachment.pgp

More information about the Twisted-web mailing list