[Chandler-dev] Harmful usage of len()

Grant Baillie grant at osafoundation.org
Wed Jun 6 10:41:45 PDT 2007


On 5 Jun, 2007, at 22:00, Heikki Toivonen wrote:

> There are lots and lots of cases in our code where we use len() to
> determine if a collection, list, tuple, string etc. is empty or not.
> This is wasteful; it is much better to check if the item in  
> question is
> empty. Python even has a special method for it, __nonzero__.
>
> Also, doing a len() on some objects causes side effects to happen that
> you may not want, like creating repository indexes (of course avoiding
> index creation in one spot will likely just move it to another spot
> which you may not want).

In case of misunderstanding:

On IRC today, Andi pointed out that the repository never creates  
indexes unless you explicitly ask it to. There is, however Chandler  
Collection code that creates repository indexes in __len__, which is  
what Heikki was talking about.

--Grant




More information about the chandler-dev mailing list