liveBook · Manning

Leading underscore convention

The leading underscore convention prefixes an identifier with an underscore to signal intended internal or non-public use without enforcing access restrictions.

How 2 Manning books explain it

Web Components in Action

How it is used
Signals which Web Component properties and methods consumers should treat as internal rather than part of the public API.
How deep it goes
Distinguishes convention-based signaling from actual privacy and demonstrates internal state behind setters.
Examples
Uses _addItemToUI, _searchTerm, _apiKey, public setters, and redraw behavior as concrete examples.
What you can do after
Apply it by naming internal component state and methods with underscores while exposing deliberate public properties.

Read how Web Components in Action explains leading underscore convention →

Python How-To

How it is used
Signals that class methods or attributes are intended for internal use and reduces irrelevant IDE autocomplete suggestions.
How deep it goes
Defines the naming convention and its autocomplete effects, while stopping short of enforcing access restrictions.
Examples
Uses _format_note, protected class members, and a challenge to rename applicable methods as nonpublic.
What you can do after
Apply it via Python naming conventions to communicate which methods and attributes users should avoid calling directly.

Read how Python How-To explains leading underscore convention →

Also covered in

What to know first

Related concepts

Questions about leading underscore convention

What is leading underscore convention?

The leading underscore convention prefixes an identifier with an underscore to signal intended internal or non-public use without enforcing access restrictions.

Which Manning books explain leading underscore convention?

Web Components in Action and Python How-To.

What should I know before learning leading underscore convention?

Manning books that teach leading underscore convention usually introduce module, attribute, Python and class first.

What is the difference between leading underscore convention and private field?

The leading underscore convention prefixes an identifier with an underscore to signal intended internal or non-public use without enforcing access restrictions. A JavaScript private field is a class field declared with a leading # that can be accessed only from within the class that declares it.

What is leading underscore convention a kind of?

Leading underscore convention is a kind of convention. A convention is an accepted or agreed practice for organizing, naming, or implementing things consistently.

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.