[Zope-CMF] classic idiom ?

Tres Seaver tseaver@palladion.com
Tue, 7 Aug 2001 16:35:30 -0400 (EDT)


On Wed, 8 Aug 2001, Florent Guillaume wrote:

> [probably a basic zope question but...]
> 
> 
> I notice the following idiom in several places, for instance in
> folder_contents.dtml or folder_rename_form.dtml :
> 
> >            portalish="_.hasattr( obj, 'isPortalContent' )
> >                       and obj.isPortalContent"
> 
> Does it behave differently from 
> 
> 	     portalish="_.getattr(obj, 'isPortalContent', 0)"
> 
> Or is it juste "suboptimal" code ? :-)

It is potentially weaker in the face of races than your code,
as 'getattr' with a default is "atomic" at the Python level;
since Zope isolates threads anyway, it is just, as you note,
"suboptimal".

Patches accepted :)

Tres.
-- 
===============================================================
Tres Seaver                                tseaver@zope.com
Zope Corporation      "Zope Dealers"       http://www.zope.com