Dear list,

Le vendredi 21 décembre 2012 21:22:31 UTC+1, kcrisman a écrit :
>
>
>> That's a substantial difference, IMHO. 
>>
>> If you do a+b, then Python calls a.__add__(b). So, Python being object 
>> oriented, you can easily overload the a.__add__ method. Sage has the 
>> class sage.structure.element.RingElement, which overloads the 
>> __add__ method, and if you sub-class it, you should in fact implement 
>> _add_ with single underscore. 
>>
>> But max is a Python builtin *function*. Overloading it by something else 
>> would break a lot of things, and I guess performance would suffer, if 
>> you overload max() by a function that first checks whether one of the 
>> arguments is a symbolic expression. 
>>
>
> Thanks, Simon, for this great explanation - that is essentially the 
> argument given at http://trac.sagemath.org/sage_trac/ticket/6949 where 
> this was implemented.
>

So, if I follow you, Sage's add was designed from the start to be 
overloaded by class methods, whereas the need for overloading Sage's max 
 id not appear until "too late". Hence it is a (small) design flaw.

As for the performance : class matching and method dispatching would occur 
every time a hypothetical max method would be used, and this is considered 
bad performance-wise. May I note that fundamentally identical class 
matching and method dispatching occurs every time one uses '+' (or any 
other arithmetic method or method-implemented operator), and that this is 
not thought|felt to hinder performance ? I have trouble isualizing this 
double standard...

Furthermore, the frequency of use of max and related  non-methods is 
probably small compared to the frequency of use of arithmetic operators, 
which *are* implemented as class methods ; I strongly doubt that such a 
class implementation would entail noticeable performance drop.

I do agree, however, that fixing this would probably not be easy (and no, I 
have not (yet) studied the code, and probably won't for a long while).

-- 
You received this message because you are subscribed to the Google Groups 
"sage-support" group.
To post to this group, send email to sage-support@googlegroups.com.
To unsubscribe from this group, send email to 
sage-support+unsubscr...@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-support?hl=en.


Reply via email to