[issue3439] create a numbits() method for int and long types

Fredrik Johansson report at bugs.python.org
Tue Oct 14 17:38:21 CEST 2008


Fredrik Johansson <fredrik.johansson at gmail.com> added the comment:

> One other note:  in Fredrik's patch there's commented out code for a 
> numbits *property* (rather than a method).  Is there any good reason to 
> make this a property?

Aesthetically, I think numbits as a function would make more sense.
(Maybe if the hypothetical imath module comes along...)

> Since numbits() cost is O(n) with n: number of digits. I prefer a 
> method than a property because, IMHO, reading a property should be 
> O(1) (*read* an attribute is different than *compute* a value).

Unless I missed something, numbits() is O(1). Only the topmost word in a
number needs to be examined.

> reading a property should be O(1) (*read* an attribute is different
> than *compute* a value).

O(1) is necessary but not sufficient. My sense is that an attribute
should access an existing "part" of an object while an operation that
involves creating a "new" object should be a method. Compare
complex.real/.imag and complex.conjugate().

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue3439>
_______________________________________


More information about the Python-bugs-list mailing list