Issue 8638: Remove suggestion for name mangling from the tutorial (original) (raw)

Created on 2010-05-06 20:00 by LucianU, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (8)
msg105161 - (view) Author: Lucian Ursu (LucianU) Date: 2010-05-06 20:00
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.
msg105164 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2010-05-06 20:31
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.
msg105191 - (view) Author: Skip Montanaro (skip.montanaro) * (Python triager) Date: 2010-05-07 11:13
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.
msg105240 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2010-05-07 22:35
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.
msg105243 - (view) Author: Clovis Fabricio (nosklo) * Date: 2010-05-07 22:39
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++.
msg105261 - (view) Author: Fred Drake (fdrake) (Python committer) Date: 2010-05-08 04:52
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
msg105283 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2010-05-08 12:54
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).
msg112179 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2010-07-31 18:26
No objections noted, closing.
History
Date User Action Args
2022-04-11 14:57:00 admin set github: 52884
2010-07-31 18:26:36 georg.brandl set status: pending -> closedmessages: +
2010-05-08 12:54:55 georg.brandl set status: open -> pendingnosy: + georg.brandlmessages: +
2010-05-08 04:52:05 fdrake set nosy: + fdrakemessages: +
2010-05-07 22:39:33 nosklo set nosy: + nosklomessages: +
2010-05-07 22:35:34 terry.reedy set nosy: + terry.reedymessages: +
2010-05-07 11:13:39 skip.montanaro set nosy: + skip.montanaromessages: +
2010-05-06 23:46:14 meatballhat set nosy: + meatballhat
2010-05-06 20:31:47 eric.araujo set nosy: + eric.araujomessages: +
2010-05-06 20:00:31 LucianU create