On Wednesday, May 28, 2014 7:23:20 AM UTC-7, Volker Braun wrote:
>
> Non-underscore attributes implement a mutable interface.
>
I wasn't aware of that convention. Is it documented somewhere, with 
rationale?

I've indeed seen "constant" instance attributes accessed via accessors and 
was aware of the following reasons:

 - An accessor method allows a docstring to be attached, so it provides a 
documentation hook. This is something we could find a solution to.

 - For a while access via calling something was faster (once 
CachedMethodNoArgs was optimized), but this was due to cython classes not 
participating in Pythons attribute lookup cache. This has since been 
corrected.

 - In cython, it's often desirable to have a cdef attribute store the 
actual data, for optimized access. If declaring that "public" for some 
reason doesn't work propery (or because the code predates that feature 
being available in cython), there will be an underscore attribute and 
routines to make it available to the python world.

Python's primary mechanism for storing information on instances is via 
attributes stored in the instance __dict__. Do we really want to dissuade 
people from using the most straightforward storing method by default? The 
"consenting adults" doctrine of Python suggests we shouldn't do that just 
to enforce immutability. 

In fact, the dynamic class machinery may store bound methods in instance 
dictionaries! Those are mutable and reassigning those can wreak real havoc.

-- 
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/d/optout.

Reply via email to