is python Object oriented??

Marc 'BlackJack' Rintsch bj_666 at gmx.net
Sun Feb 1 03:04:42 EST 2009


On Sat, 31 Jan 2009 09:08:25 -0800, thmpsn.m.k wrote:

> On Jan 30, 12:15 am, Chris Rebert <c... at rebertia.com> wrote:
>> - Python supports encapsulation. Prefixing an attribute/method with an
>> underscore indicates that other programmers should treat it as
>> 'private'. However, unlike B&D languages, Python itself does nothing to
>> enforce this privacy, leaving it instead to the good judgement of the
>> programmer, under the philosophy that "We're all consenting adults
>> here".
> 
> How do you know? (I know I'm not.)

Then stay with B&D languages.  :-)

> Seriously, though, the lack of private members does allow for ugly hacks
> in user code, and you know there are always ugly hackers.

So what?  The hacks in Java to access private fields are even uglier IMHO.

>> This allows people to meddle with internals, at their own risk, if it
>> ends up being absolutely necessary.
> 
> If it ends up being necessary, the class's design is flawed.

Maybe that's the reason why it is really necessary.

> (Though in this case, the flaw is easily solved by simply providing a
> getter.)

Simply providing a getter for a private attribute?  I thought that's not 
easily possible in C++ or Java!?  ;-)

>> The enforcement point is
>> largely academic anyway, as most languages' reflection APIs let you
>> poke at ostensibly "private" things.
> 
> If you're talking about getters, then note that this doesn't let you
> modify the member (unless there's a corresponding setter).

It's not about getters but about accessing private fields without any 
getters or setters through the reflection API.  See the article 
`Subverting Java Access Protection for Unit Testing`_ for examples.

.. _Subverting Java Access Protection for Unit Testing:
    http://www.onjava.com/pub/a/onjava/2003/11/12/reflection.html

Ciao,
	Marc 'BlackJack' Rintsch



More information about the Python-list mailing list