I would say that it's fine, especially in a subclass.
David
On Thu, Jun 4, 2015 at 9:23 AM, Bruno Grenet <bruno.gre...@gmail.com> wrote:

>  Dear all,
>
> Many classes in SageMath (most of them? all of them? I don't know...) have
> their attributes hidden by a leading `__`. Yet in Python hidden attributes
> are never really hidden, since it is possible to access the attribute
> `__hidden` of the class `MyClass` as `_MyClass__hidden`.
>
> What SageMath's policy about using these hidden attributes in functions?
>
> *A concrete example: *
>
> For sparse polynomials (class `Polynomial_generic_sparse` in
> `src/sage/rings/polynomial/polynomial_element_generic.py`), the
> coefficients are stored as a dictionary, stored in the attribute
> `__coeffs`. To compute the number of nonzero monomials, one can use any of
> the following three solutions:
>
>    1. sage: len(p.coefficients()) # builds the list of (nonzero)
>    coefficients, and computes its length
>    2. sage: len(p.dict()) # copies the dictionary __coeffs and computes
>    its length
>    3. sage: len(p._Polynomial_generic_sparse__coeffs) # computes the
>    length of __coeffs
>
> As one can expect, the fastest is solution 3. To get an idea of the
> differences, with a random degree-10000 polynomial over ZZ, I get using
> `timeit`:
>
>    1. 1.11 ms
>    2. 174 µs
>    3. 88 ns (with slowest run 46.05 times longer than fastest)
>
> Thus if I implement a method `number_of_terms` in the class
> `Polynomial_generic_sparse`, I am tempted to implement the third solution.
> But is referring to a hidden attribute an issue?
>
> Cheers,
> Bruno
>
> --
> 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.
>

-- 
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