Christoph Zwerschke wrote: > thakadu schrieb: > > I have used PyMeld (http://www.entrian.com/PyMeld/) which is one of > > very few that gives a 100% separation of code and presentation, in fact > > PyMeld is not strictly speaking a template system at all. > > Yes, it is more like XIST that I mentioned in another post. > The reason why this is slower than native templates seems clear: You > convert the whole page to objects in memory, and then serialize > everything back to HTML.
PyMeld's not a good example to judge DOM-style templating by: the main reason it's a poor performer is its implementation is very inefficient. There's a couple of third-party redesigns kicking about the web if you want to search for them; I've not tried them myself but I imagine performance is one of the issues they address. It is true that DOM-style templating engines will still tend to be a bit slower at rendering than a macro-style templating engine even when all else is equal, but that's a price you always pay for choosing a dynamic over a static approach. For example, I once did some quick-n-dirty comparisons for my own HTMLTemplate engine [1] which is fairly well optimised pure Python code, and reckon its performance on typical insertion and iteration tasks is maybe 1/2 - 1/3 of Cheetah's. (IIRC, PyMeld ran up to 100x slower in those particular tests due to its naive algorithms.) OTOH, you have to remember that HTML rendering is only one small component in the overall application, so you really have to consider this against the performance of the rest of the application to know if a 2-3x difference in rendering speed makes a significant difference or not. Chances are the biggest bottlenecks will lie elsewhere. Besides, if pedal-to-the-metal performance is your primary concern, you should probably be writing everything in C++ anyway. > If you are only filling in a few words, then > native templates will be surely much more effective. But if you are > messing around with the structure of your page, inserting and adding > elements, then PyMeld will be probably a better way. I dunno; DOM-style engines work fine even for simple jobs, while the big macro-style engines can do a lot of fancy stuff too. I think the major difference is that the DOM-style engines do things much more simply. For example, HTMLTemplate's codebase, API and documentation are maybe a tenth the size of Cheetah's. Rather than trying to provide every possible feature users might ever want themselves (c.f. Greenspun's Tenth Rule), they keep out of the way as much as possible and let the original language provide for the user's needs. HTH -- [1] http://freespace.virgin.net/hamish.sanderson/htmltemplate.html -- http://mail.python.org/mailman/listinfo/python-list