Are mangled names necessary?
- Dominant language
- Python
- Stars
- 953
- Forks
- 91
- PR merge metrics
- No merged PRs in 30d
Description
Double underscore variables like these: https://github.com/klen/mixer/blob/374a503915405d6fb7c2a9d7765650e3b94ce7ac/mixer/main.py#L88
Are being used extensively in the TypeMixer class.
According to the docs, the official use case for those mangled names is ["to avoid name clashes of names with names defined by subclasses"](https://docs.python.org/2/tutorial/classes.html#private-variables-and-class-local-references).
However, this is not how those are used in the mixer library. Methods like `__load_fields` are overridden in almost every subclass. Since the method names gets mangled, all subclasses are forced to call themselves TypeMixer as well in order to get around the mangling.
I just spent a few hours figuring this surprising behavior out, and I don't see any real benefits to forcing subclasses to call themselves "TypeMixer" for them to work. Am I missing something? If there is a real benefit here, it would be great if there is some sort of highly visible documentation for developers who wish to subclass TypeMixers.
---
Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/40628090-are-mangled-names-necessary?utm_campaign=plugin&utm_content=tracker%2F327725&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F327725&utm_medium=issues&utm_source=github).
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with mixer/main.py at line 88 and inspect how TypeMixer subclasses override methods such as __load_fields. Compare that behavior with Python's documented private-variable name mangling; done means reaching a decision about the mangling and documenting the subclassing requirement or changing the approach with appropriate tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- testing
- Issue type
- Refactor
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100