Name mangling
Name mangling is the transformation of identifiers into altered names to encode distinguishing information or reduce naming collisions.
Refactoring to Rust
Name mangling is the compiler transformation of symbols into unique names that encode additional implementation information.
- How it is used
- Enables Rust functions to retain predictable symbol names so C code can link to them.
- How deep it goes
- Defines mangling through symbol uniqueness and collisions, gives a Rust symbol example, and leaves the compiler’s naming method unexplained.
- Examples
- Uses Rust’s `solve` function and its mangled symbol as examples of an exported function name.
- What you can do after
- Apply `#[no_mangle]` to keep an exported Rust function’s symbol unmangled for C linkage.
Software Design for Python Programmers
Python name mangling is the transformation of double-underscore class attribute names to include the defining class name.
- How it is used
- Uses double leading underscores to protect class attributes from accidental collisions in subclasses.
- How deep it goes
- Defines the transformation and design rationale, but does not show the mangled spelling or its runtime internals.
- Examples
- Uses Catalogue.__booklist as the protected-subclass example, contrasting it with Book and Catalogue single-underscore members.
- What you can do after
- Evaluate when double leading underscores reduce accidental attribute collisions during subclass design.
Read how Software Design for Python Programmers explains name mangling →
The Quick Python Book, Fourth Edition
Name mangling is Python's transformation of names beginning with two underscores by prepending a class-based prefix to reduce accidental access and inheritance collisions.
- How it is used
- Reduces accidental access to double-underscore attributes and distinguishes private names across class hierarchies.
- How deep it goes
- Defines the naming rule and demonstrates transformed names and access behavior, while clarifying that mangling is not enforced privacy.
- Examples
- Demonstrates `Mine.__y`, method access, `dir(m)`, and private members in a superclass and subclass.
- What you can do after
- Apply it by naming instance variables or methods with leading double underscores to reduce accidental access.
Read how The Quick Python Book, Fourth Edition explains name mangling →
Related concepts
- no_mangleaddressed by · no_mangle is a Rust attribute that prevents name mangling for an item, preserving its symbol name in compiled output.
- private memberused by · A private member is a program element whose direct access is restricted to its defining class, module, file, or other language-defined scope.
- namespace collisionaddresses · A namespace collision occurs when distinct software entities use the same identifier within a shared naming scope, causing ambiguity or conflict.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.


