#11316: Weighted degree term orders added
--------------------------------+-------------------------------------------
   Reporter:  klee              |          Owner:  AlexGhitza  
       Type:  enhancement       |         Status:  needs_review
   Priority:  minor             |      Milestone:  sage-4.7.1  
  Component:  basic arithmetic  |       Keywords:              
Work_issues:                    |       Upstream:  N/A         
   Reviewer:                    |         Author:  Kwankyu Lee 
     Merged:                    |   Dependencies:              
--------------------------------+-------------------------------------------

Comment(by SimonKing):

 Replying to [comment:11 klee]:
 > I kept double underscores in the new patch. I don't know why Martin do
 not like double underscore attributes. Do you think single underscore
 attributes are generally preferable over double ones? Or is it just for
 fixing unpickling problem.

 As Martin said, double underscore attributes can be a problem in sub-
 classes. To be precise: We talk about an attribute whose name starts with
 two underscores but ends with less than two underscores. It is a Python
 convention that those attributes are private. And in order to emphasize
 the privacy, Python applies so-called name mangling (easy to google): The
 attribute name is mangled with the name of the class ''for which it was
 originally defined''.

 By consequence, there is a problem for subclasses:
 {{{
 sage: class A:
 ....:     def __init__(self,n):
 ....:         self.__n = n
 ....:
 sage: class B(A):
 ....:     def __init__(self,n):
 ....:         A.__init__(self,n^2)
 ....:
 sage: b = B(5)
 sage: b.__n
 ---------------------------------------------------------------------------
 AttributeError                            Traceback (most recent call
 last)

 /home/king/<ipython console> in <module>()

 AttributeError: B instance has no attribute '__n'
 }}}
 So, surprise: `__n` seems gone. But it is there, under a different name:
 {{{
 sage: b._A__n
 25
 }}}

 It is obvious that, under these circumstances, single underscore names are
 easier to deal with.

 Remark: No mangling occurs if the name ''ends'' with two underscores.
 That's why all the magical methods `__repr__`, `__add__` etc. can be
 easily inherited.

-- 
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/11316#comment:14>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica, 
and MATLAB

-- 
You received this message because you are subscribed to the Google Groups 
"sage-trac" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sage-trac?hl=en.

Reply via email to