[Zope] re: Length of results set

Dylan Reinhardt zope@dylanreinhardt.com
Fri, 17 Jan 2003 09:28:29 -0800


>If DTML is considered scripting and Python programming, why do some say 
>that DTML is harder than Python? I am comfortable with the verbosity - 
>some call it ugliness - of DTML. Of course the expression above is more 
>elegant than its equivalent in DTML, could someone give me an idea of the 
>'cost differential' between this and the solution below proposed by Dylan 
>Reinhardt?

I gave a solution in DTML since that's what you asked for.  It doesn't 
necessarily follow that DTML is going to be the best solution in most 
cases.  :-)

I would recommend Dieter's solution (use a Python script) for most 
non-trivial cases.  I doubt there's a huge performance benefit either way, 
but the Python scripts will be far easier to maintain over the long 
run.  Pretty much any time you find yourself going more than two or three 
levels deep in your logic, it's time to move it out of DTML.... but for 
code maintainability and validation, not for performance.

That holds true of ZPT too.  DTML and ZPT should be thought of as 
*presentation layer* tools.  When you find yourself performing logic in 
your presentation layer, you would be well-advised to consider whether 
you're performing strict presentation logic or whether you're performing 
business logic.

Business logic, generally speaking, should not be performed in your 
presentation layer even if it *could* be done that way.  You'll be best off 
if you use DTML (and/or ZPT) for templating and little else.  The flow 
control built into DTML is great for iterating over data sets, but 
shouldn't be confused with a robust set of programming tools.

>Maybe I persist with DTML and overlook its 'ugliness' because I find DTML 
>embedding convenient as opposed to the combination of Script (Python) + 
>ZPT. I promise to advance with Python, but I vote to keep DTML!

It's not so much a matter of whether DTML should exist, but what it's a 
good tool for.  Having mastered DTML, many new Zopistas are tempted to 
over-use it.  The best advice to offer here is: Don't.

HTH,

Dylan


At 02:35 AM 1/17/2003, you wrote:
> >> How do you get the length of results for a <dtml-if> inside a <dtml-in> ?
>
>Dieter Maurer wrote:
>
> > You do *NOT* do this in DTML!
> >
> > In Python, you simple count all positive hits in a loop:
> >
> >    i= 0
> >    for o in context.objectValues():
> >      if ...: i+= 1
> >    return i
> >
> > You see, how easy it is in Python?
>
>Dieter, you make it *look* easy!
>
>
> > <dtml-call "REQUEST.set('my_result', [])">
> > <dtml-in objectValues>
> > <dtml-if "id==something">
> > <dtml-call "my_result.append(something)">
> > </dtml-if>
> > </dtml-in>
>
>
>Ken
>
>
>
>_______________________________________________
>Zope maillist  -  Zope@zope.org
>http://lists.zope.org/mailman/listinfo/zope
>**   No cross posts or HTML encoding!  **
>(Related lists -
>  http://lists.zope.org/mailman/listinfo/zope-announce
>  http://lists.zope.org/mailman/listinfo/zope-dev )