liveBook · Manning

Global variable

A global variable is a variable whose binding is accessible from broad program or module scope according to the language’s name-resolution rules.

How 12 Manning books explain it

The Well-Grounded Rubyist, Fourth Edition

A global variable is a Ruby variable identified by a leading dollar sign and accessible globally according to Ruby's variable semantics.

How it is used
Distinguishes program-wide variable access from local scope and identifies Ruby’s built-in state variables.
How deep it goes
Works through cross-scope access, built-in examples, and thread-local exceptions without cataloging every built-in global.
Examples
Uses a top-level assignment read inside a class method and numbered captures from a regular-expression match.
What you can do after
Diagnose/debug with `global_variables` to list global names and recognize which familiar globals are thread-local.

Read how The Well-Grounded Rubyist, Fourth Edition explains global variable →

Grokking Simplicity

A variable whose binding is accessible across broad program or module scope rather than being confined to a single function or block.

How it is used
Uses global variables as a practical target for improving testability, reuse, and asynchronous behavior.
How deep it goes
Explains globals through implicit inputs and outputs, then demonstrates argument passing, local state, returned copies, and timeline isolation.
Examples
Uses shopping carts, tax calculation, shipping icons, asynchronous totals, local variables, arguments, and copy-on-write.
What you can do after
Apply explicit arguments, local variables, and return values to reduce global mutable state and improve reuse and debugging.

Read how Grokking Simplicity explains global variable →

Python Workout: 50 ten-minute exercises

A global variable is a variable defined outside a function and accessible through the module's global scope.

How it is used
Explains how Python resolves names across functions, modules, globals, and built-ins.
How deep it goes
Works through LEGB, local shadowing, explicit global assignment, built-in collisions, and imported names.
Examples
Uses Python Tutor frames, inner and outer x values, a global counter-style update, sum shadowing, and os imports.
What you can do after
Diagnose/debug with Python Tutor by tracing global and local frames, detecting shadowed names, and predicting function effects.

Read how Python Workout: 50 ten-minute exercises explains global variable →

Modern C, Third Edition

A global variable is a C object with program-wide or file-wide lifetime and visibility determined by its linkage and scope.

How it is used
Provides an object that multiple functions can manipulate when passing values alone does not share that object.
How deep it goes
Explains file scope and the design costs of shared state, without developing linkage rules or a full global-object implementation.
Examples
Uses a shared visited_entries counter and names for initialization or error-handling state.
What you can do after
Evaluate/understand whether shared file-scope state is warranted and how it affects a function’s purity.

Read how Modern C, Third Edition explains global variable →

Grokking AI Applications

A named value managed centrally so it can be reused across multiple Langflow flows.

How it is used
Centralizes values such as API keys for reuse across multiple Langflow flows and external application connections.
How deep it goes
Explains creation, naming, credential selection, encryption, reuse, updating, deletion, and display limits for encrypted values.
Examples
Demonstrates storing an OpenAI API key as an encrypted credential and reusing it across flows.
What you can do after
Operate/configure Langflow to store shared API keys once and reuse them across flows.

Read how Grokking AI Applications explains global variable →

100 C++ Mistakes and How to Avoid Them

A global variable is a variable declared at global or namespace scope whose visibility can extend across functions within a compilation unit.

How it is used
Frames global variables as a practical source of shadowing, correctness problems, and maintenance difficulty.
How deep it goes
Explains compilation-unit visibility, shadowing, naming, and namespace qualification through concrete C++ listings.
Examples
Uses Circle radius listings, a setter self-assignment, namespace qualification, and a namespaced mathematical constant.
What you can do after
Diagnose shadowing and disambiguate global access with namespaces, qualification, and clearer names.

Read how 100 C++ Mistakes and How to Avoid Them explains global variable →

The Quick Python Book, Fourth Edition

A global variable is a name bound at module or program level that can be accessed and modified by functions that explicitly declare it global.

How it is used
Uses shared module-level state for cross-function updates and, in one case, caching repeated expensive calculations.
How deep it goes
Explains local-versus-global assignment, contrasts nonlocal scope, and demonstrates results without descending into interpreter internals.
Examples
Demonstrates modifying a shared scalar, preserving a local shadow, updating nested scopes, and memoizing results in a dictionary.
What you can do after
Apply it via Python to share module-level state, update it deliberately, and diagnose name-shadowing or refactoring errors.

Read how The Quick Python Book, Fourth Edition explains global variable →

Modern C

A global variable is a C variable declared outside functions whose scope extends through the remainder of its source file and whose storage normally persists for the program's execution.

How it is used
Uses global variables to identify and name persistent or shared state.
How deep it goes
Defines file scope, persistence, and naming practice, but stops short of implementation details.
Examples
Uses toto_initialized, onError, and visited_entries as names for initialization, error, and shared hash-table state.
What you can do after
Evaluate global-state names and recognize when file-scope variables may be unavoidable.

Read how Modern C explains global variable →

Python How-To

A global variable is a variable defined in a module's global scope and accessible according to the language's name-resolution rules.

How it is used
Uses global variables for module-level state, including database choices and filenames updated by functions.
How deep it goes
Explains module scope, LEGB lookup, namespace inspection, and the global declaration, but stops short of broader state-management alternatives.
Examples
Demonstrates database filenames, globals() and locals(), and an application database option changed by set_db_option.
What you can do after
Apply it via Python’s global keyword to update module-level state from a function and diagnose accidental local assignments.

Read how Python How-To explains global variable →

100 Go Mistakes and How to Avoid Them

A global variable is a variable whose scope allows access from multiple functions or locations within a package or program.

How it is used
Contrasts shared package state with encapsulated initialization and uses global state to keep benchmark calls observable.
How deep it goes
Explains mutation, test isolation, initialization errors, and benchmark optimization, stopping short of broader state-management patterns.
Examples
Uses a global database connection pool and a benchmark sink paired with a local result variable.
What you can do after
Diagnose hidden test coupling and misleading benchmarks, then replace global initialization with caller-controlled functions when appropriate.

Read how 100 Go Mistakes and How to Avoid Them explains global variable →

Rust in Action: Systems programming concepts and techniques

A global variable is a variable whose storage and scope make it accessible across multiple parts of a program.

How it is used
Uses global state to propagate error codes and urgent shutdown requests across otherwise separate parts of a program.
How deep it goes
Explains declaration syntax, unsafe access, conventions, and small runnable examples, while warning against broader global-state design.
Examples
Demonstrates file-read and file-close error checks, plus a random shutdown flag controlling a loop.
What you can do after
Apply it by declaring and accessing mutable Rust statics for error signaling or shutdown control inside unsafe blocks.

Read how Rust in Action: Systems programming concepts and techniques explains global variable →

Get Programming: Learn to code with Python

A global variable is a variable bound in the global scope and accessible from code whose name resolution reaches that scope.

How it is used
Explains how functions find variables and distinguish main-program values from same-named function variables.
How deep it goes
Works through scope rules, access, shadowing, failed assignment, nested functions, and an execution trace.
Examples
Uses same-named `peter` variables, readable scope listings, failed modification, nested functions, and an odd-or-even trace.
What you can do after
Diagnose variable-resolution results and explain why function reads, local shadowing, or assignments succeed or fail.

Read how Get Programming: Learn to code with Python explains global variable →

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.