As Victor Stinner mentioned in a recent thread, there's a patch in
the works to add a numbits ... um ... gadget to integers, returning
the number of bits needed to represent the integer (or more
precisely, the ceiling of the log to base 2 of the integer).  See

http://bugs.python.org/issue3439

Question for python-dev: if numbits were to be added, should it
be a property or a method? (Or something else entirely?)

More generally, what are the guidelines for determining
when it's appropriate to make something a property rather
than a method?

In favour of numbits being a (read-only, of course) property:

  - it looks nicer that way
  - it's a fast O(1) method, so is comparable to an attribute access
    in terms of efficiency
  - it can reasonably be thought of as a fundamental property of
    a binary integer
  - there are precedents, as Raymond points out in the issue
    discussion:  e.g. z.real, z.imag

Thoughts?

Mark
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to