D
D.M. Procida
What exactly is the point of a private method? Why or when would I want
to use one?
Daniele
to use one?
Daniele
What exactly is the point of a private method? Why or when would I want
to use one?
Daniele
http://stackoverflow.com/questions/2620699/why-private-methods-in-the-obMark Lawrence said:Hardly a Python question but using a search engine could have got you
here, and rather faster
In Python, using an underscore is simply a convention to note that a
method is private - it doesn't actually hide it from other things -
correct?
Daniele
http://stackoverflow.com/questions/2620699/why-private-methods-in-the-ob
ject-oriented
Thanks. Sometimes I prefer to talk to real people on Usenet than do web
searches. Just my preference.
Anyway, one of the answers on that page explains that public methods are
interfaces to a class, that other things might rely on, and private ones
are for its own internal logic, that other things don't need to care
about.
In Python, using an underscore is simply a convention to note that a
method is private - it doesn't actually hide it from other things -
correct?
In Python, using an underscore is simply a convention to note that a
method is private - it doesn't actually hide it from other things -
correct?
A single underscore semantically means private. A double underscore will
name mangle the function such that it's only accessible strictly by name
through the class that it's define in. Note that you *can* still access it
if you understand how name mangling works. Nothing in Python is truly
private.
I tend to view name mangling as being more for avoiding internal
attribute collisions in complex inheritance structures than for
designating names as private.
Really? I tend to view name mangling as a waste of time, and complex
inheritance structures as something to avoid.
Demian Brecht said:Yep, I've been coming around to this as of late.
Really? I tend to view name mangling as a waste of time, and complex
inheritance structures as something to avoid.
http://stackoverflow.com/questions/2620699/why-private-methods-in-the-ob
ject-oriented
Thanks. Sometimes I prefer to talk to real people on Usenet than do web
searches. Just my preference.
Anyway, one of the answers on that page explains that public methods are
interfaces to a class, that other things might rely on, and private ones
are for its own internal logic, that other things don't need to care
about.
In Python, using an underscore is simply a convention to note that a
method is private - it doesn't actually hide it from other things -
correct?
(e-mail address removed) (D.M. Procida) wrote:
Yes (modulo some details of how import works that I've never fully
figured out and which lack of knowledge hasn't seemed to have hurt me
any).
I view public and private in Python this way:
Public: I hereby declare that this method or attribute is part of the
promised never to change interface of this class. I might possibly
break that promise at some point in the future, but if I do, you have
the right to bitch and whine about it, and I'm morally obligated to at
least pretend I care.
Private: I hereby declare that this method or attribute is something I
needed to have for my own purposes, and is officially hidden inside my
kimono. Like all things inside my kimono, you may speculate about their
existence all you want, but you touch them at your own peril. I may
change them at some point in the future, and while you can bitch and
whine about it all you want, I'm not listening.
Uhum. Language please.
What language?
Further the original was readable, your use of CrapMail made life
difficult until I stripped the superfluous newlines out. Is it
really so awkward to equip yourself with a semi-decent mail reader?
Like Thunderbird, hint, hint
It certainly makes it quick to build a class with the attributes I need,
but it does make tracing logic sometimes a pain in the neck.
I don't know what the alternative is though.
What language?
Components.
What exactly is the point of a private method? Why or when would I want
alex23 said:Components.
The examples are in C++ and it's about game development, but I found
this article to be very good at explaining the approach:
http://gameprogrammingpatterns.com/component.html
I've become a big fan of components & adaptation using zope.interface:
http://wiki.zope.org/zope3/ZopeGuideComponents
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.