[Zope] lambda's in external methods
lists at zopyx.com
Wed Jan 16 12:52:37 EST 2008
--On 15. Januar 2008 20:21:44 -0700 David Bear <David.Bear at asu.edu> 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.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Size: 186 bytes
Desc: not available
Url : http://mail.zope.org/pipermail/zope/attachments/20080116/0c157bcc/attachment.bin
More information about the Zope