Re: [Zope] lambda's in external methods
David Bear wrote at 2008-1-15 20:21 -0700: >In the zope 2.7 book it mentions that an optimization technique for >external methods is to compile regular expressions in global scope to >the module. The re's will then be compiled at zope load time. > >I am wondering if the same holds for lambdas. "lambda"s are (as well as any static Python code) compiled at load time -- independent of their position. When you move the "lambda" to the top level, then the "lambda" object, too, is build at load time. Otherwise, the object is build when the function containing the "lambda" reaches the lambda. However, construction this object from the predefined pieces is not very expensive. -- Dieter ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] lambda's in external methods
--On 15. Januar 2008 20:21:44 -0700 David Bear <[EMAIL PROTECTED]> wrote: In the zope 2.7 book it mentions that an optimization technique for external methods is to compile regular expressions in global scope to the module. I don't think that this is very specific to Zope but a general recommendation for any Python application. Since compiling regexes can be expensive you want to compile then once. Defining them on the module level is the common solution. I am wondering if the same holds for lambdas. I created some simple filters using lambdas. I defined them in the functions where I use them. Is there any advantage to defining them globally to the module? I don't see any relationship between lambda expressions and regex since there is no compilation involved when dealing with lambda expressions - except the byte code compiliation however this takes place when importing a module - not at runtime. Are there any gottcha's with globally scope objects? This is a general programming question - no necessarily tied to Python. A general answer might be: define only those things globally that must be globally (aka void global namespace polution). Usually define some constants or something similar globally in order to avoid moving those parameters around..but it depends on the individual usecase. Andreas pgp4qIdC8tpUo.pgp Description: PGP signature ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
[Zope] lambda's in external methods
In the zope 2.7 book it mentions that an optimization technique for external methods is to compile regular expressions in global scope to the module. The re's will then be compiled at zope load time. I am wondering if the same holds for lambdas. I created some simple filters using lambdas. I defined them in the functions where I use them. Is there any advantage to defining them globally to the module? Are there any gottcha's with globally scope objects? -- David Bear phone: 602-496-0424 fax:602-496-0955 College of Public Programs/ASU University Center Rm 622 411 N Central Phoenix, AZ 85007-0685 "Beware the IP portfolio, everyone will be suspect of trespassing" ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )