[Zope] Use of lambda expression in DTML

Lalo Martins lalo@hackandroll.org
Tue, 30 May 2000 00:40:39 -0300


On Mon, May 29, 2000 at 10:58:54PM -0400, Chris McDonough wrote:
> 
> > <dtml-in "_.map (lambda item: Catalog.getobject (item.data_record_id_),
> >         Catalog (REQUEST)">
> 
> 
> How could someone understand this when you're finished with it?

Perfectly clearly for anyone used to functional programming;
I'd even say, clear on first sight. A lot easier to understand
and maintain than a separate method.

> Isn't this much more understandable as an external method explicitly?

No. And external methods should definitely be phased out as
much as possible, they defeat one of the major advantages of
Zope (everything is manageable trought the web).

> def return_cataloged_objects(self):
>     obs = []
>     catalog = self.Catalog
>     request = self.REQUEST
>     for r in catalog(request):
>         d_rid = r.data_record_id_
>         ob = catalog.getobject(d_rid)
>         obs.append(ob)
> 
>     return obs

Your method, in particular, is worse to understand than my
one-liner, specially for anyone who uses functional programming
seriously; but even other people would have to reason for a
few minutes to understand what you're appending to that poor
list and why.

Reading functional programming requires a paradigm shift as
much as reading OOP; but if you can handle it, it's definitly
worth your time.


> Maybe they should... it would be nice.  I'm not sure why they're not in
> Python Methods, other than Evan tried to make the security inherent in
> Python methods as close to DTML as he could.  I use map a lot.  I don't
> use lambda unless I really, really have to.  Reduce and filter.. eh.  I
> dunno.  They're sort of on the periphery of usefulness.

I respect the fact that you have your opinion where DTML is
going and where it should go and where it shouldn't. But I
don't think it is an excuse to cripple it. It is, instead, your
opinion, as much as mine is mine.

Yes, expressions make DTML less clear and walk around caching.

No, they shouldn't be banned. They're useful. Ban them and all
you get is either a code fork or a considerable number of lost
users.

You compare these to ASP, PHP or Perl. I compare them to
__getattr__, __getitem__, __call__ and others on Python, and to
operator overloading in C++. Think whatever you want.

[]s,
                                               |alo
                                               +----
--
          Hack and Roll  ( http://www.hackandroll.org )
            News for, uh, whatever it is that we are.


http://zope.gf.com.br/lalo           mailto:lalo@hackandroll.org
         pgp key: http://zope.gf.com.br/lalo/pessoal/pgp

Brazil of Darkness (RPG)    ---     http://zope.gf.com.br/BroDar