liveBook · Manning

Name mangling

Name mangling is the transformation of identifiers into altered names to encode distinguishing information or reduce naming collisions.

How 3 Manning books explain it

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.

Read how Refactoring to Rust explains name mangling →

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

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.