[Erp5-dev] [Erp5-report] r26242 - in /erp5/trunk/products/ERP5: Tool/ tests/

Julien Muchembled jm at nexedi.com
Thu Apr 2 17:48:26 CEST 2009


Yoshinori Okuji a écrit :
> On Thursday 02 April 2009 23:34:33 Julien Muchembled wrote:
>> * In almost all cases, 'cmp' is _much_ slower that 'key'. In the rare cases
>> where using 'cmp' could be faster, it is possible to write a 'key' func
>> that behaves like a 'cmp': cf http://code.activestate.com/recipes/576653/
>> (Convert a cmp function to a key function).
> 
> I don't care about whether it is fast or slow. The fact is that it is quite 
> difficult to write a key function in some cases.

In almost all cases, key functions are smaller, and easier to write. To test according several properties (one after the other, until a difference is found), you can return a list.
The recipe could be used when the key form is slower or hard to maintain.

> Note that the complexity of 
> the workaround given there is equal to using cmp.

I know.

>> * 'cmp' parameter doesn't exist in Python 3 (and I suppose it will also
>> disappear in a future 2.x version). I know this is really far future but it
>> appears we already need to convert existing code due to performance issues.
>>
>> Knowing all this, it is not serious to keep using 'cmp' in new code.
> 
> Not at all. You can recommend using key whenever feasible, but you should not 
> force to use key only.

Enforcing things avoid the need to document and avoid the case where someone didn't read that document.

Here, the performance hit is so high that we shouldn't allow people using a cmp function by mistake.

Also, I don't like the idea of adding countless feature-parameters to API method just because that parameter might useful one day. sort_key_method is enough for DomainTool.searchPredicateList.


BTW, this is my last mail on this subject because I have no time to discuss further. Do what you want.


Julien



More information about the Erp5-dev mailing list