use of properties

John Arbash Meinel john at arbash-meinel.com
Thu Jan 5 03:16:45 GMT 2006


Martin Pool wrote:
> On Thu, 2006-01-05 at 13:00 +1100, Robert Collins wrote:
> 
>>Hi, 
>>	We seem to have some varied uses of properties. I'd like to draw
>>everyones attention to a recent PEP8 change, which is that properties
>>should not be used for anything that has non trivial performance
>>implications. (To me, this means anything that reads or writes from disk
>>should never be a property).
>>
>>The thing that got me dropping this mail to the list is 'branch.nick'
>>which can potentially take many seconds on slow transports: a get and
>>set method is entirely appropriate here.
> 
> 
> I second that.  I don't think the presence of just get_x and set_x
> implies that you should instead have a property x (as it might in other
> languages).  I'm not sure precisely what the criteria should be, but I
> would suggest being careful in adding them.  The one that I added,
> tree.inventory, was possibly a mistake.
> 
> One reasonable justification may be that you want to avoid breaking
> callers who expect a field, but to add more behaviour.  Obviously this
> implies it should still have similar semantics and behaviour to a field.
> 

I've actually thought of it also as a way to create a readonly property
(when you only have get).

I've used that in places like 'Branch.base' since you shouldn't be able
to set it (it would actually have limited effect anyway, since
_transport is where the information is).

But I agree, a property *feels* like it is just a variable, and thus
shouldn't have expensive side effects.

John
=:->
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 256 bytes
Desc: OpenPGP digital signature
Url : https://lists.ubuntu.com/archives/bazaar/attachments/20060104/8670794d/attachment.pgp 


More information about the bazaar mailing list