Is behavior of += intentional for int?

Z

zaur

Python 2.6.2 (r262:71600, Apr 16 2009, 09:17:39)
[GCC 4.0.1 (Apple Computer, Inc. build 5250)] on darwin
Type "copyright", "credits" or "license()" for more information.
a=1
x=[a]
id(a)==id(x[0]) True
a+=1
a 2
x[0]
1

I thought that += should only change the value of the int object. But
+= create new.
Is this intentional?
 
P

Paul McGuire

Python 2.6.2 (r262:71600, Apr 16 2009, 09:17:39)
[GCC 4.0.1 (Apple Computer, Inc. build 5250)] on darwin
Type "copyright", "credits" or "license()" for more information.>>> a=1
x=[a]
id(a)==id(x[0]) True
a+=1
a 2
x[0]

1

I thought that += should only change the value of the int object. But
+= create new.
Is this intentional?

ints are immutable. But your logic works fine with a mutable object,
like a list:
a = [1]
x = [a]
print id(a) == id(x[0]) True
a += [1]
print a [1, 1]
print x[0]
[1, 1]

What exactly are you trying to do?

-- Paul
 
G

Günther Dietrich

zaur said:
Python 2.6.2 (r262:71600, Apr 16 2009, 09:17:39)
[GCC 4.0.1 (Apple Computer, Inc. build 5250)] on darwin
Type "copyright", "credits" or "license()" for more information.
a=1
x=[a]
id(a)==id(x[0]) True
a+=1
a 2
x[0]
1

I thought that += should only change the value of the int object. But
+= create new.
Is this intentional?

An integer variable contains the reference (ID) to an (immutable)
integer object; it doesn't contain the value itself. So, when you assign
a new value to an integer variable, it will contain the reference to the
object containing the new value, afterwards.

If you assign an integer variable to a list element, this reference will
be written into the list. The assignment of a new value to the integer
variable will create a new integer object, containing the new value, and
put the reference to it into the integer variable.
The reference to the object with the old value, that is stored in the
list, won't be touched.


In fact, it is a result of integers in python being immutable.



Best regards,

Günther
 
Z

zaur

Paul McGuire said:
What exactly are you trying to do?

I think, he wants to kind of dereference the list element. So that he
can write

instead of
long_name_of_a_list_which_contains_data[mnemonic_pointer_name] += 1

Regards,

Günther

That's right. I thought that int as object will stay the same object
after += but with another integer value.
My intuition said me that int object which represent integer value
should behave this way.
But by design python's integer behave differently.

I fond that NumPy's 1-d types behaves as objects with mutable values.
from numpy import *
a=array([1])
id(a) 10912544
a += 1
id(a) 10912544
a
array([2])
 
S

Steven D'Aprano

I thought that int as object will stay the same object after += but with
another integer value. My intuition said me that int object which
represent integer value should behave this way.

If it did, then you would have this behaviour:

5

This would be pretty disturbing behaviour, and anything but intuitive.

Fortunately, Python avoids this behaviour by making ints immutable. You
can't change the object 3 to have any other value, it will always have
value three, and consequently n+=1 assigns a new object to n.
 
A

AggieDan04

Python 2.6.2 (r262:71600, Apr 16 2009, 09:17:39)
[GCC 4.0.1 (Apple Computer, Inc. build 5250)] on darwin
Type "copyright", "credits" or "license()" for more information.>>> a=1
x=[a]
id(a)==id(x[0]) True
2

I thought that += should only change the value of the int object. But
+= create new.
Is this intentional?

ints are immutable.  But your logic works fine with a mutable object,
like a list:

Technically, mutability isn't the issue: There's nothing enforcing
that a mutable object HAS to have an __iadd__ method that returns the
same object.
 
D

Derek Martin

If it did, then you would have this behaviour:

No, you wouldn't; the behavior you described is completely different
from, and incompatible with, what zaur wrote.

He's saying that instead of thinking the integer value of 3 itself
being the object, he expected Python's object model would behave as
though the entity m is the object, and that object exists to contain
an integer value. In that case, m is always m, but it has whatever
integer value it is told to hold at any point in time. The
self-referential addition would access the value of m, add the
operand, and store the result back in the same object as the object's
value. This is not the way Python works, but he's saying this is the
intuitive behavior. I happen to agree, and argued at length with you
and others about that very thing months ago, when some other third
party posted with that exact same confusion.

By contrast, your description maintains the concept of numerical value
as object that Python uses, and completely misses the point. I did
find the description you gave to be highly enlightening though... It
highlighted perfectly, I think, exactly why it is that Python's behavior
regarding numerical values as objects is *not* intuitive. Of course,
intuition is highly subjective.

I believe it boils down to this: People expect that objects they
create are mutable. At least, unless they specify otherwise. It is
so in some other programming languages which people may be likely to
be familiar with (if they are not taking their first forray into the
world of computing by learning Python), and even "real world" objects
are essentially always mutable. If you have a 2002 Buick LeSabre, it
has a number of attributes, including its length, which might be 8.5
feet, for instance. However, this is not fixed: by adding modified
body parts, or as an extreme example by sawing off the trunk of the
car, the length and indeed the object itself has been changed.
However, despite having been modified, it is at least in some sense
still the same object: it is still a 2002 Buick LeSabre, and it still
has the same *identity* (the same VIN number). It's the same object,
but its value(s) changed. [Not that it matters, but I do not own such
a car. :)]

Numbers are fundamentally different from objects. The number 3 is a
symbol of the idea of the existence of three countable objects. It
can not be changed (though it can be renamed, if you so choose -- just
don't expect most people to know what you're talking about). It is
unintuitive that 3 is an object; it is rather what we use to describe
objects -- the value of the object. It is an abstract concept, and
as such it is not an object at all. You cannot hear 3, taste
3, nor smell 3. You can neither see nor touch 3, though you can
certainly see 3 *objects* if they are present, and you can certainly
see the symbol '3' that we use to represent that idea... but you can
not see three itself, because there is no such object. The only way
to see three is to envision 3 of some object. The number 3 does not
have a value; it IS a value (it is the symbolic representation of the
value of three). To say that 3 is an object that has a value is a bit
like saying the length of a car is an object that itself has a length.
It just doesn't compute.

THAT is why Python's behavior with regard to numerical objects is
not intuitive, and frankly bizzare to me, and I dare say to others who
find it so.

Yes, that's right. BIZZARE.

Of course, none of this is real. In the end, it's all just a bunch of
wires that either have current or don't. It's only how *WE* organize
and think about that current that gives it any meaning. So you're
free to think about it any way you like.

--
Derek D. Martin
http://www.pizzashack.org/
GPG Key ID: 0x81CFE75D


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (GNU/Linux)

iD8DBQFKmisxdjdlQoHP510RAnBtAJ4+6wzI+o4+QhYsRXTvmSPZaKlIzQCdGNET
f3sv2YuP4HVKmOSkBWYvHZQ=
=fXce
-----END PGP SIGNATURE-----
 
M

Mark Dickinson

If it did, then you would have this behaviour:


5

I don't see how that follows. In an alternative interpretation, the
int literals would all be thought of as distinct objects: that is,
the line 'n = 3' creates an integer object with value 3 and binds the
name n to it; the later line 'm = 3' then creates another *new*
integer object with value 3 and binds the name m to it. In other
words, it could work in exactly the same way as the following works in
Python:
n = {}
n[1729] = 10585
m = {}
m
{}

The modification to n doesn't affect m, since the two occurrences of
{} give distinct dictionary objects.
 
S

Steven D'Aprano

No, you wouldn't; the behavior you described is completely different
from, and incompatible with, what zaur wrote.

He's saying that instead of thinking the integer value of 3 itself being
the object, he expected Python's object model would behave as though the
entity m is the object, and that object exists to contain an integer
value.

What is "the entity m"?

Is it the name m, as follows?

Or is it the literal "3" (without quotes)?

Or an object holding the value three?

Or something else?

In that case, m is always m,
but it has whatever integer value
it is told to hold at any point in time. The self-referential addition
would access the value of m, add the operand, and store the result back
in the same object as the object's value.

Ah wait, I think I get it... is m a memory location? So when you say:

m = 3

the memory location that m represents is set to the value 3, and when you
say:

m += 1

the memory location that m represents is set to the value 4?

That would be how Pascal and C (and presumably other languages) work, but
not Python or Ruby or even VB (so I'm told) and similar languages. Java
has a hybrid model, where a few data types (such as ints) are handled
like C, and everything else is handled like Python. Consistency was never
Java's strong suit.

This is not the way Python
works, but he's saying this is the intuitive behavior.

It isn't intuitive if you've never been exposed to Pascal- or C-like
languages. If your only programming language was Haskell, the very idea
of mutating values would be alien. So I guess when you say "the intuitive
behaviour", what you actually mean is "familiar".

I happen to
agree, and argued at length with you and others about that very thing
months ago, when some other third party posted with that exact same
confusion.

By contrast, your description maintains the concept of numerical value
as object that Python uses, and completely misses the point. I did find
the description you gave to be highly enlightening though... It
highlighted perfectly, I think, exactly why it is that Python's behavior
regarding numerical values as objects is *not* intuitive. Of course,
intuition is highly subjective.

What exactly is it about Python's behaviour regarding numbers that is not
intuitive? That you can't do this?
anum = 2
alist = [anum]
anum += 1
print alist # this doesn't work
[3]

That won't work in any language that I know of -- as far as I am aware,
the above is impossible in just about every common programming language.
(My C and VB are nearly non-existent, so I may be wrong about them.) Here
is Ruby's behaviour:

irb(main):001:0> anum = 2
=> 2
irb(main):002:0> alist = [anum]
=> [2]
irb(main):003:0> anum += 1
=> 3
irb(main):004:0> puts alist
2
=> nil


Just like Python.

I believe it boils down to this: People expect that objects they create
are mutable.

Why would they expect that? Is there any evidence apart from the
anecdotal complaints of a few people that they expect this? People
complain equally when they use a mutable default value and it mutates, or
that they can't use mutable objects as dict keys, so this suggests that
people expect objects should be immutable and are surprised when they
change.

If you're going to argue by analogy with the real world (as you do
further on), I think it's fair to argue that some objects are mutable
(pieces of rubber that expand into a balloon when you blow into them),
and some are immutable unless you expend extraordinary effort (rocks). I
would be gobsmacked if my desk turned pink or changed into an armchair, I
expect it to be essentially unchanging and immutable. But I fully expect
a banana to turn black, then squishy, and finally white and fuzzy if I
leave it long enough.

At least, unless they specify otherwise. It is so in some
other programming languages which people may be likely to be familiar
with (if they are not taking their first forray into the world of
computing by learning Python), and even "real world" objects are
essentially always mutable.
[snip example of a 2002 Buick LeSabre]

Be careful bringing real-world examples into this. People have been
arguing about identity in the real-world for millennia. See, for example,
the paradox of my great-grandfather's axe. My great-grandfather's axe is
still in my family after 80 years, as good as new, although the handle
has been replaced four times and the head twice. But it's still the same
axe. An even older example is the paradox of the Ship of Theseus.

Numbers are fundamentally different from objects. The number 3 is a
symbol of the idea of the existence of three countable objects. It can
not be changed

Doesn't this contradict your claim that people expect to be able to
mutate numbers? That you should be able to do this?
123456


You can't have it both ways -- if people think of objects as mutable, and
think of numbers as not-objects and unchanging, then why oh why would
they find Python's numeric behaviour to be unintuitive?

(though it can be renamed, if you so choose -- just don't
expect most people to know what you're talking about). It is
unintuitive that 3 is an object;

Says you. People have considered numbers to be eternal, unchanging,
immutable entities going back to at least Plato. If people are
comfortable thinking that there are Platonic ideal numbers, why wouldn't
they think of them represented in computers as immutable objects?

What I think is that some people, such as you and Zaur, have *learned*
from C-like languages that numbers are mutable not-objects, and you've
learned it so well that you've forgotten that you ever needed to learn
it. Consequently what you actually mean when you say Python is
unintuitive is that Python is not like some other language (and is like
yet other languages).

it is rather what we use to describe
objects -- the value of the object. It is an abstract concept, and as
such it is not an object at all. You cannot hear 3, taste 3, nor smell
3. You can neither see nor touch 3, though you can certainly see 3
*objects* if they are present, and you can certainly see the symbol '3'
that we use to represent that idea... but you can not see three itself,
because there is no such object.

Human beings are excellent at reifying abstract things into (imaginary)
objects. We talk about letting in the cold (we actually let out the
heat); we talk about souls and life-force as if they are things; we treat
justice and love and mercy and hate as palpable things instead of
emotions and abstract entities. Plato imagined that everything has a
pure, abstract form, an ideal, and people find that intuitive: we expect
that there is an archetypal "chair" that embodies everything that is
chair-like and nothing which is not, if only we could find it.

Numbers are no different. Reifying them into objects comes easy to people
who haven't learned differently.

The only way to see three is to
envision 3 of some object. The number 3 does not have a value; it IS a
value (it is the symbolic representation of the value of three). To say
that 3 is an object that has a value is a bit like saying the length of
a car is an object that itself has a length.

No, the length of a car is an object which *is* a length, it doesn't
*have* a length.

It just doesn't compute.

None of this explains why you would expect to be able to mutate the value
three and turn it into four.

I don't think your argument makes sense -- I think your explanation is
tangled up in knots. Everything you say about numbers being unchangeable,
immutable entities supports Python's behaviour to make numbers immutable,
and yet you argue that since people expect numbers to be unchanging, they
therefore expect Python ints to be mutable! This makes no sense.

THAT is why Python's behavior with regard to numerical objects is not
intuitive, and frankly bizzare to me, and I dare say to others who find
it so.

Yes, that's right. BIZZARE.

I think you have confused yourself. If the number three cannot change,
and you have a label "m" associated with three, then if you add one to
it, you *can't* have the three mutate into a four, because numbers cannot
change. Obviously the label has to detach itself off the three and onto
the four -- precisely the behaviour Python uses. Plato would surely have
found this commonsensical, and I would say that it's only those who have
become used to Pascal-like languages that don't.
 
P

Paul McGuire

THAT is why Python's behavior with regard to numerical objects is
not intuitive, and frankly bizzare to me, and I dare say to others who
find it so.

Yes, that's right.  BIZZARE.

Can't we all just get along?

I think the question boils down to "where is the object?". In this
statement:

a = 3

which is the object, a or 3?

There exist languages (such as C++) that allow you to override the '='
assignment as a class operator. So that I could create a class where
I decided that assigning an integer value to it applies some
application logic, probably the setting of some fundamental
attribute. In that language, 'a' is the object, and 3 is a value
being assigned to it. This can cause some consternation when a reader
(or worse, maintainer) isn't familiar with my code, sees this simple
assignment, and figures that they can use 'a' elsewhere as a simple
integer, with some surprising or disturbing results.

Python just doesn't work that way.

Python binds values to names. Always. In Python, "=" is not and never
could be a class operator. In Python, any expression of LHS = RHS,
LHS is always a name, and in this statement it is being bound to some
object found by evaluating the right hand side, RHS.

The bit of confusion here is that the in-place operators like +=, -=,
etc. are something of a misnomer - obviously a *name* can't be
incremented or decremented (unlike a pointer in C or C++). One has to
see that these are really shortcuts for LHS = LHS + RHS, and once
again, our LHS is just a name getting bound to the result of LHS +
RHS. Is this confusing, or non-intuitive? Maybe. Do you want to write
code in Python? Get used to it. It is surprising how many times we
think things are "intuitive" when we really mean they are "familiar".
For long-time C and Java developers, it is intuitive that variables
are memory locations, and switching to Python's name model for them is
non-intuitive.

As for your quibble about "3 is not an object", I'm afraid that may be
your own personal set of blinders. Integer constants as objects is
not unique to Python, you can see it in other languages - Smalltalk
and Ruby are two that I know personally. Ruby implements a loop using
this interesting notation:

3.times do
...do something...
end

Of course, it is a core idiom of the language, and if I adopted Ruby,
I would adopt its idioms and object model.

Is it any odder that 3 is an object than that the string literal
"Hello, World!" is an object? Perhaps we are just not reminded of it
so often, because Python's int class defines no methods that are not
"__" special methods (type in "dir(3)" at the Python prompt). So we
never see any Python code referencing a numeric literal and
immediately calling a method on it, as in Ruby's simple loop
construct. But we do see methods implemented on str like split(), and
so "about above across after against".split() gives me a list of the
English prepositions that begin with "a". We see this kind of thing
often enough, we get accustomed to the objectness of string literals.
It gets to be so familiar, it eventually seems "intuitive". You
yourself mentioned that intuition is subjective - unfortunately, the
"intuitiveness" of a feature is often tied to its value as a coding
concept, and so statements of non-intuitiveness can be interpreted as
a slant against the virtue of that concept, or even against the
language itself.

Once we accept that 3 is an object, we clearly have to stipulate that
there can be no changes allowed to it. 3 must *always* have the value
of the integer between 2 and 4. So our language invokes the concept
that some classes create instances that are immutable.

For a Python long-timer like Mr. D'Aprano, I don't think he even
consciously thinks about this kind of thing any more; his intuition
has aligned with the Python stars, so he extrapolates from the OP's
suggestion to the resulting aberrant behavior, as he posted it.

You can dispute and rail at this core language concept if you like,
but I think the more entrenched you become in the position that "'3 is
an object' is bizarre", the less enjoyable your Python work will be.

-- Paul
 
S

Steven D'Aprano

I don't see how that follows.

Okay, it follows given Python's caching of small integer objects.

It also follows from the idea that there is one abstract entity which
English speakers call "three" and write as 3. There's not two identical
entities with value 3, or four, or a million of them, only one.

But of course your alternative implementation (where every time the
Python VM sees the literal 3 it creates a new integer object with that
value) would also be a valid, albeit inefficient, implementation. To be
honest, I didn't even think of that.
 
P

Paul McGuire

Python binds values to names. Always. In Python, "=" is not and never
could be a class operator.  In Python, any expression of LHS = RHS,
LHS is always a name, and in this statement it is being bound to some
object found by evaluating the right hand side, RHS.
An interesting side note, and one that could be granted to the OP, is
that Python *does* support the definition of class operator overrides
for in-place assignment operators like += (by defining a method
__iadd__). This is how numpy's values accomplish their mutability.
It is surprising how many times we
think things are "intuitive" when we really mean they are "familiar".
Of course, just as I was typing my response, Steve D'Aprano beat me to
the punch.

Maybe it's time we added a new acronym to this group's ongoing
discussions: PDWTW, or "Python doesn't work that way".

-- Paul
 
A

Albert Hopkins

It also follows from the idea that there is one abstract entity which
English speakers call "three" and write as 3. There's not two
identical
entities with value 3, or four, or a million of them, only one.

That's not true. There are many different 3s in all the parallel
universes. ;)

-a
 
C

Carl Banks

THAT is why Python's behavior with regard to numerical objects is
not intuitive, and frankly bizzare to me, and I dare say to others who
find it so.

Yes, that's right.  BIZZARE.

You mean it's different from how you first learned it.


Carl Banks
 
C

Carl Banks

What is "the entity m"?

I think they (Derek and zaur) expect integer objects to be mutable.

It's pretty common for people coming from "name is a location in
memory" languages to have this conception of integers as an
intermediate stage of learning Python's object system. Even once
they've understood "everything is an object" and "names are references
to objects" they won't have learned all the nuances of the system, and
might still (not unreasonably) think integer objects could be mutable.

However, it'd be nice if all these people didn't post here whining
about how surprising and unintuitive it is and instead just said, "ah,
integers are immutable, got it", quietly to themselves.


Carl Banks
 
Z

zaur

If it did, then you would have this behaviour:


5

This would be pretty disturbing behaviour, and anything but intuitive.

Fortunately, Python avoids this behaviour by making ints immutable. You
can't change the object 3 to have any other value, it will always have
value three, and consequently n+=1 assigns a new object to n.

This behavior is because small integers are cached internally. See

Python 2.6.2 (r262:71600, Apr 16 2009, 09:17:39)
[GCC 4.0.1 (Apple Computer, Inc. build 5250)] on darwin
Type "help", "copyright", "credits" or "license" for more information.(16793992, 16793992, 17067336, 17067276)
 
A

Albert Hopkins

It's pretty common for people coming from "name is a location in
memory" languages to have this conception of integers as an
intermediate stage of learning Python's object system. Even once
they've understood "everything is an object" and "names are references
to objects" they won't have learned all the nuances of the system, and
might still (not unreasonably) think integer objects could be mutable.
I agree. Python (and other similar languages?) are different in that.
'x' does not point to an area in memory, where you can do anything with
that area. But in Python there are objects, and they are "references"
in memory that some magical "reference counter" keeps track of for us
(and that's a wonderful thing). And what is 'x'? Well 'x' is just some
"label" that just so happens to have the privelage of being associated
with this "unnamed" object. 'x' could just as easily associate itself
with another object.

I think that the Blue programming language, which I have been looking at
lately, makes this distinction even clearer. For example, functions are
not defined by names at all. Instead of

def funcname(): ...

You have

func{...};

If you actually want to be able to reference the function later (as you
probably would) then it's just a simple assignment just like any other
assignment:

funcname = func{...};

But i think it makes it more clear that "funcname" just so happens to
reference this object that's a function. It's the same basic philosophy
when applied to methods:

MyClass = sys.class();
MyClass.my_method = func{...};

Blue also has interesting, simple rules wrt scopes. It's a surprisingly
small, simple language (yet in a very early stage of development.
However, it'd be nice if all these people didn't post here whining
about how surprising and unintuitive it is and instead just said, "ah,
integers are immutable, got it", quietly to themselves.

Yes, when I was first learning Python, at least the book I used made it
very clear when introducing a new type to specify that type as mutable
or immutable. It's a very core concept to Python. If you choose to
ignore it or refuse to understand it then you are asking for trouble.

-a
 
Z

zaur

I think they (Derek and zaur) expect integer objects to be mutable.

It's pretty common for people coming from "name is a location in
memory" languages to have this conception of integers as an
intermediate stage of learning Python's object system.  Even once
they've understood "everything is an object" and "names are references
to objects" they won't have learned all the nuances of the system, and
might still (not unreasonably) think integer objects could be mutable.

However, it'd be nice if all these people didn't post here whining
about how surprising and unintuitive it is and instead just said, "ah,
integers are immutable, got it", quietly to themselves.

Carl Banks

Very expressive.

I use python many years. And many years I just took python int as they
are.
I am also not think about names as reference to objects and so on.

So this isn't the case.
 
D

Derek Martin

What is "the entity m"?

The entity m is an object. Objects, in computer science, are
abstractions created by humans to make solving a large class of
problems easier to think about. An object is a piece of data, upon
which you can perform programmatic actions, which are grouped together
with the values contained in that data. It's an abstraction which
translates, in the physical sense, to a group of memory locations with
a reference in a symbol table.
Ah wait, I think I get it... is m a memory location?

No, it isn't. It is an abstraction in the programmer's mind that sits
on top of some memory. For that matter, the memory location is
itself an abstraction. It is not a memory location, but a particular
series of circuits which either have current or don't. It is simply
convenient for us to think of it as a memory location.
That would be how Pascal and C (and presumably other languages)
work, but not Python or Ruby or even VB (so I'm told) and similar
languages.

Well, except that, in fact, they do work that way. They simply
present a different abstraction to the programmer than C or other
languages. They have to work that way, at the lowest level, because
that is how the hardware works.
Doesn't this contradict your claim that people expect to be able to
mutate numbers? That you should be able to do this?

This is where you continually fail. There is no contradiction at all.
What I'm saying is that in my view, numbers CAN'T mutate; they are not
objects! They are values, which are a means of describing objects.
Only the objects which hold the values can mutate. However in Python
they don't, and can't, but they EASILY could with a different design.
You, however, seem to be completely stuck on Python's behavior with
regard to numeric objects, and fail to see past that. Python's model
is only one abstraction, among multiple possibilities.
You can't have it both ways -- if people think of objects as
mutable, and think of numbers as not-objects and unchanging, then
why oh why would they find Python's numeric behaviour to be
unintuitive?

Because in Python, they ARE objects, which they think should be
mutable, but in Python when they try to change the *value* of the
object, they don't get the same object with a different value; they
get a completely different object. This is counter to their
experience. If you don't like the Buick example, then use algebra.
We've been down this road before, so I'm probably wasting my time...
In algebra, you don't assign a name to a value, you assign a value to
a variable. You can, in a different problem, assign a different value
to that variable, but the variable didn't change; only its value did.
In Python, it's the opposite.
What I think is that some people, such as you and Zaur, have *learned*
from C-like languages that numbers are mutable not-objects, and you've
learned it so well that you've forgotten that you ever needed to learn
it.

No, this is precisely why I provided the real-world examples -- to
illustrate to you that there was no need to learn it in computer
science, because the concept applies in the real world quite
intuitively in every-day situations. I think rather it is YOU who
have learned the concept in Python, and since then fail to imagine any
other possible interpretation of an object, and somehow have
completely forgotten the examples you encountered before Python, from
algebra and from the real world.
Human beings are excellent at reifying abstract things into (imaginary)
objects.

I don't know what the word "reifying" means, but irrelevant. Such
things are abstract, and in fact not objects.
No, the length of a car is an object which *is* a length, it doesn't
*have* a length.

It is not an object. It is an abstract idea used as a description of
an object.
None of this explains why you would expect to be able to mutate the
value three and turn it into four.

Again, you fail. I *DO NOT* expect that. I expect to be able to
mutate the object m, changing its value from 3 to 4.
I think you have confused yourself.

No Steven, on this topic, it is only you who have been confused,
perpetually. Although, it could be said that Python's idea of what an
object is also is itself confused... Python (or at least the docs)
actually refrains from formally defining an object. The docs only say
that an object has an identity, a name, and a value. Well, OK... so 3
is an object. You can bind a name to it... except that's not exactly
correct. You can bind many names to it, and every time you write
something like:

m = 3

You are binding another name to the same object. That's intuitive?
So you say. But what is the value of 3? Is it 3? How can the value
of an object be the object itself? If that were true, then the value
of the object is an object, which has a value... you have an infinite
recursion. It's a paradox. How could you get any more unintuitive
than that?!

In practice it's not a paradox, because the values inside numeric
objects are *not* objects. They're numerical constants, as used by
the hardware (excepting that they are just an abstraction on top of
current, as noted before). Python's model breaks down at that point;
it is not so with most other types of objects... their values remain
objects. And *that* is inconsistent. The same is true of character
data as for numeric data. And that, I believe, is why Java treats
these as atomic data types, rather than as objects. Because they are,
in fact. They are types of data that the hardware knows how to deal
with, directly. Everything else is not.

--
Derek D. Martin
http://www.pizzashack.org/
GPG Key ID: 0x81CFE75D


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (GNU/Linux)

iD8DBQFKmquSdjdlQoHP510RAjU2AJsGtTbm/1muucyFrgsSGEyu8U6ZOgCgu7Xx
v0SrQNs4I8TxP09482kseKc=
=Gf1F
-----END PGP SIGNATURE-----
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top