[Python-Dev] Mini-Pep: Simplifying the Integral ABC (original) (raw)

Guido van Rossum guido at python.org
Fri Jun 6 22🔞13 CEST 2008


On Fri, Jun 6, 2008 at 11:40 AM, Alex Martelli <aleaxit at gmail.com> wrote:

On Fri, Jun 6, 2008 at 11:01 AM, Guido van Rossum <guido at python.org> wrote:

On Thu, Jun 5, 2008 at 8:45 PM, Raymond Hettinger <python at rcn.com> wrote:

Does anyone actually need an int lookalike with binary methods but cannot just inherit from int?

Does anyone actually need an int lookalike with operations like +, - etc. but cannot just inherit from int? If the answer is yes, is there a compelling reason why they wouldn't want to support binary methods as well? Yes, there's a use case for implementing long integers as arrays of decimal digits -- addition is roughly as efficient as for binary integers (x86 chips still have instructions to help with that), and emitting as decimal digits is MUCH more efficient of course -- so if I/O in decimal form is the most common operation, with a little arithmetic (particularly sums), you could gain performance;

I tried this with ABC in '83. We didn't see any of the hoped-for benefits though. That's why Python has binary long integers. :-)

binary operations, however, would be as inefficient as decimal form conversion is for ordinary binary ints, and not needed for the typical applications that would use these "decimal coded integers" (accounting), so why not save the implementer of such an extension from having to write that unneeded and slow extra code?

You could just raise an exception. This is common in Java when an Interface requires you implement a method you can't. Or use virtual inheritance from the Integral class and leave them unimplemented. See if anyone cares. :-)

-- --Guido van Rossum (home page: http://www.python.org/~guido/)



More information about the Python-Dev mailing list