Is behavior of += intentional for int?

Piet van Oostrum piet at cs.uu.nl
Mon Aug 31 12:04:01 CEST 2009


>>>>> Derek Martin <code at pizzashack.org> (DM) wrote:

>DM> On Sun, Aug 30, 2009 at 03:42:06AM -0700, Paul McGuire wrote:

>>> Is it any odder that 3 is an object than that the string literal
>>> "Hello, World!" is an object?  

>DM> Yes.  Because 3 is a fundamental bit of data that the hardware knows
>DM> how to deal with, requiring no higher level abstractions for the
>DM> programmer to use it (though certainly, a programming language can
>DM> provide them, if it is convenient).  "Hello, World!" is not.  They are
>DM> fundamentally different in that way.

How the semantics of Python is defined is not dependent of the hardware.
You could imagine a computer where strings are as much built into the
hardware as ints are. On the other hand you could also imagine a
computer that only knows about bits and where int arithmetic has to be
done in software. In fact early microprocessors only could operate
directly on bytes and arithmetic of larger ints was in software. And
even nowadays there are processors in use that don't have built-in
floating point hardware. Would you say that considering whether 3.14 is
an object in Python or whether that is to be considered strange should
depend on the availability of a floating point unit in the hardware
where the program runs? Would that make floating point numbers
"fundamentally different" from ints in the sense described above?
-- 
Piet van Oostrum <piet at cs.uu.nl>
URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
Private email: piet at vanoostrum.org



More information about the Python-list mailing list