can someone explain?

Alex Martelli aleaxit at yahoo.com
Tue Feb 18 07:00:06 EST 2003


Pastula Pawe³ wrote:

>> When you do a "val += 1", you're creating a new integer
>> object which has a value (val+1) and assigning it's
>> "address" (or it's reference, as it's known in this
>> group) to the name "val".
> 
> Yes it makes sense. I just thought that integer values are treated
> differently (like in Java).
> Does it mean that there are only 2 ways of changing a value in a function?
> 1st: return val+1
> 2nd: to place a value in a class and then pass instance of this class to e
> function.
> Is it correct?

Not quite.  Just like in Java, e.g., you can always pass a
list (in Java you could pass an array) containing only that
value -- and, many other such dirty-ish tricks.

> There is still one thing I'm thinking about.
> Why did Python authors abandoned encapsulation in classes?

They (actually, he) didn't "abandon" it, but, rather, never
accepted it as a useful concept.

> public, private and protected modifiers are quite useful, and what's the

Oh yeah -- SO useful, that Stroustrup himself, the designer
of C++, put it in writing (in his excellent book about C++'s
Design and Evolution) that he REGRETS introducing "protected".

> most important, make debugging much easier and faster.

No way.  It's extremely easy for a tool to spot usage of
a private-by-convention attribute (one whose name starts
with an underscore) if you're worried about that.  Indeed
EXACTLY because there's no such idiocy as private/public/...
in Python, it's possible for you to write an automatic wrapper
class that does it automatically for you to help you debug
by tracing all accesses &c.  Now trying to do that in C++
(good luck inserting all needed "friend" declarations before
you recompile the universe...).  Pah.


Alex





More information about the Python-list mailing list