On Saturday, September 14, 2013 8:59:38 PM UTC+1, Simon King wrote: > > It is not so obvious to me that one should think of Sage categories > as=20 > > having nothing to do with mathematical categories and being just a > > form of syntactic sugar. > I am also not so happy with this formulation. It is similar to Python > inheritence, since it actually *provides* inheritance.
No it doesn't, and not having this point stressed confused me for a long time. Inheritance always piles on stuff: Subclasses are their base classes plus more. And that is precisely what categories don't give you: You can stick the base class into one category C1 and the derived class in a different category C2, and the derived class will not know the slightest about C1. I read the following blog post a while back, and it really clarified things to me (in part precisely because it neither talks about math nor Python): http://cowboyprogramming.com/2007/01/05/evolve-your-heirachy/ Coming back to the original question, should something be implemented as method of RingElement or as Rings.ElementMethod? Often, both is feasible. In principle, we could do away with RingElement: All elements just inherit from Element and use categories to get their module/ring operations. But that would also raise the barrier of entry for Sage significantly, as it is much more difficult to write a first implementation of some ring structure that already correctly uses the category machinery. Also, you lose Cython type checking since you can only check for Cython classes. And using inheritance for Elements from the comparatively small Element hierarchy is rather easy to use. To summarize, the rule should be: attach methods to the Element hierarchy if there is a "perfect fit". If not (that is, if your method doesn't make sense for each and every ring) then put it in the appropriate SpecialRings.ElementMethod. -- You received this message because you are subscribed to the Google Groups "sage-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+unsubscr...@googlegroups.com. To post to this group, send email to sage-devel@googlegroups.com. Visit this group at http://groups.google.com/group/sage-devel. For more options, visit https://groups.google.com/groups/opt_out.