Newbie Q: Class Privacy (or lack of)

Ray ray_usenet at yahoo.com
Thu Jul 27 01:56:16 EDT 2006


Hey Steve,

Yes, I agree with you. The lack of checking can get confusing fast.
It's not about typing without errors. Regardless of how you train as
long as you're human you WILL make typos.

Also having to check whether a name has already existed can be a major
pain in the butt with Python. With Java you always know when a name has
already existed, and what type is bound to the name. I consider this to
be a Good Thing (tm).

Regarding the lack of privacy, I actually like the C++ way of doing it.
Privacy is there, but you have the choice to break it (using "friend")
if you want/need to. C++ doesn't make it easy for you to do it
inadvertently, like you described in the example.

The argument against this is that since development with Python is so
rapid, you're supposed to always equip your code with extensive unit
tests. I like Python but I've never really bought that argument--I
guess I've been doing Java too long :)

Cheers
Ray


Steve Jobless wrote:
> Sybren Stuvel wrote:
> >
> > Steve Jobless enlightened us with:
> > > The first case can be just a typo, like:
> > >
> > >   x.valeu = 5
> > >
> > > I make typos all the time. Without a spell checker, this message
> > > would be unreadable :).
> >
> > Then learn to read what you type, as you type it. Typing without
> > errors can be trained.
>
> I'd rather let a machine to do that. Wasn't computer created for tasks
> like this? (No, not really. But...)
>
> >
> > > The second case can be like:
> > >
> > >   x.next = y
> > >   y.next = None
> > >
> > > to create a linked list by piggybacking "next" to the class. It will
> > > overwrite the iterater for the class if defined.
> >
> > You shouldn't simply pick a name and assign something to it without
> > checking the current use of that name. It's pretty much true for
> > everything in life.
>
> Well, the choice of "next" was not a good example. Sure, no one with
> decent Python knowledge would do that.
> But what about adding a method to the class? Am I supposed to ask "Is
> anyone using name xxx?" The class may be used by  developers I don't
> even know and some of them may be on the other side of the planet...
>
> >
> > > If I was working on a large project with many engineers, I'd assume
> > > someone will do things like this sooner or later. I've seen many
> > > horrendous code in my life and I have no control over who I work
> > > with.
> >
> > Long live a versioning system. With that, you can find the person
> > writing the horrible code, and slap them on the back of the head.
> > People, like all animals, can be trained into doing the right thing.
>
> I'd like to. But often those people are long gone for one reason or
> another. Sometimes, it happens to be my boss...
>
>
> Maybe I should ask the question in a different way:
>
> What are the benefits from this? There must be something really good
> (and hopefully safe) you can do with it only from the outside. I don't
> have much problem over-riding functions from the inside of the class.
> But from the outside, I fail to see why anyone needs to add attributes
> or over-ride functions.
> 
> SJ




More information about the Python-list mailing list