S
Suresh Jeevanandam
# I am new to python.
In python all numbers are immutable. This means there is one object ( a
region in the memory ) created every time we do an numeric operation. I
hope there should have been some good reasons why it was designed this way.
But why not have mutable numbers also in the language. A type which
would behave as follows:
a = MutableInt(12)
b = a
Now both a and b should refer to the same memory location. Any change in
the object should get reflected in all the references.
a.assign(13) # Same memory location should be updated with value 13, b
is also 13 now.
Now we can further optimize:
a.incrementOne() # equivalent to a++ in C++
a.decrementOne()
and the augmented assignment operation also could be made optimized.
In any application most of the operation is numerical. So, i think, we
should get a good speed advantage with the availability of mutable
numbers. What do you think ?
regards,
Suresh
In python all numbers are immutable. This means there is one object ( a
region in the memory ) created every time we do an numeric operation. I
hope there should have been some good reasons why it was designed this way.
But why not have mutable numbers also in the language. A type which
would behave as follows:
a = MutableInt(12)
b = a
Now both a and b should refer to the same memory location. Any change in
the object should get reflected in all the references.
a.assign(13) # Same memory location should be updated with value 13, b
is also 13 now.
Now we can further optimize:
a.incrementOne() # equivalent to a++ in C++
a.decrementOne()
and the augmented assignment operation also could be made optimized.
In any application most of the operation is numerical. So, i think, we
should get a good speed advantage with the availability of mutable
numbers. What do you think ?
regards,
Suresh