[issue8638] Remove suggestion for name mangling from the tutorial

New submission from Lucian Ursu <lucian_ursu@yahoo.com>: I suggest that name mangling should not be recommended as a way of having private attributes. Instead, one underscore should be suggested as a signal that the attribute is private. This suggestion comes after discussing with some of the helpers from #python. Basically, they said that name mangling should never be used, so it would be appropriate to remove this recommendation from the tutorial. ---------- assignee: docs@python components: Documentation messages: 105161 nosy: LucianU, docs@python priority: normal severity: normal status: open title: Remove suggestion for name mangling from the tutorial type: feature request versions: Python 2.6 _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue8638> _______________________________________

Éric Araujo <merwok@netwok.org> added the comment: Note that the opinion of people helping in #python does not necessarily (or frequently) match the one of core Python developers. That said, I agree with this particular suggestion. ---------- nosy: +merwok _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue8638> _______________________________________

Changes by Dan Buch <daniel.buch@gmail.com>: ---------- nosy: +meatballhat _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue8638> _______________________________________

Skip Montanaro <skip@pobox.com> added the comment: Maybe the wording should be changed, but name mangling serves a useful purpose. There are two definitions of "private" which seem to be a bit conflated in this section: * "private" as in, "this name is not part of the public API - use it at your own risk". * "private" as in, "I don't want someone to accidentally stomp on this attribute name when subclassing this class". I think it is valuable to mention both of these conventions in the tutorial for a couple reasons: * the tutorial is meant for people new to Python but with experience in other programming languages * the distinction between _a and __a is a bit subtle and not obviously similar to privacy features present in other languages. I work with a lot of C++ programmers who also write some Python (sometimes a lot of Python). It's clear at times that the distinction hasn't always sunk in. ---------- nosy: +skip.montanaro _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue8638> _______________________________________

Terry J. Reedy <tjreedy@udel.edu> added the comment: Double underscore name mangling is for avoiding name clashes with base classes, not for 'private attributes'. This is such an advanced and rarely used feature that it hardly seems appropriate for the tutorial. ---------- nosy: +tjreedy _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue8638> _______________________________________

On Fri, May 7, 2010 at 6:35 PM, Terry J. Reedy <report@bugs.python.org> wrote:
This is such an advanced and rarely used feature that it hardly seems appropriate for the tutorial.
The problem with just leaving it out is that learners stumbling over them in existing code (likely by trying to use something that looks like it should be there and getting an AttributeError) won't have a chance of knowing what the problem might be. I'd be fine seeing new uses discouraged, especially for new learners, but I think it's important that they be given a heads-up as well. -Fred -- Fred L. Drake, Jr. <fdrake at gmail.com> "Chaos is the score upon which reality is written." --Henry Miller

Clovis Fabricio <nosklo+python@gmail.com> added the comment: I help in #python and always suggest people to not use double-underscore name mangling when they mean private. I agree that name mangling shouldn't be on the tutorial at all. It misleads everybody coming from other languages into thinking that it means "private" like it does in java or C++. ---------- nosy: +nosklo _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue8638> _______________________________________

Georg Brandl <georg@python.org> added the comment: The section titled "Private Variables" was updated fairly recently to be more in line with the Python philosophy. In its current form (which I verified to be present at e.g. http://docs.python.org/tutorial/classes#private-variables) I don't think it needs to be removed or revised (except for further clarification, of course.) If someone disagrees, I would like to see a patch (or a suggestion for new wording). ---------- nosy: +georg.brandl status: open -> pending _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue8638> _______________________________________

Georg Brandl <georg@python.org> added the comment: No objections noted, closing. ---------- status: pending -> closed _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue8638> _______________________________________
participants (8)
-
Clovis Fabricio
-
Dan Buch
-
Fred Drake
-
Georg Brandl
-
Lucian Ursu
-
Skip Montanaro
-
Terry J. Reedy
-
Éric Araujo