liveBook · Manning

Constant

A constant is a named program value or binding that is fixed or intended not to change after initialization.

How 3 Manning books explain it

The Well-Grounded Rubyist, Fourth Edition

A constant is a Ruby identifier whose name begins with an uppercase letter and conventionally denotes a value intended not to be reassigned.

How it is used
Names classes and stores shared class data while making nested values reachable through class or module paths.
How deep it goes
Works through assignment, reassignment warnings, object mutation, and relative versus absolute lookup.
Examples
Uses a class’s venue array, Math::PI, and nested X definitions to illustrate storage and lookup.
What you can do after
Evaluate/understand Ruby constant lookup and distinguish reassignment warnings from changes to referenced objects.

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

Modern C

A named constant is a constant associated with an explanatory name representing a particular meaning.

How it is used
Uses names to preserve distinct meanings, improve maintenance, and identify constants as significant artifacts.
How deep it goes
Defines naming principles and surveys enumeration constants, macros, and temporary objects without detailing their syntax.
Examples
Uses repeated 3 values, named string arrays, and identifiers such as corvid_num, M_PI, false, true, SIZE_MAX, and fortytwo.
What you can do after
Evaluate which repeated values require names and distinguish enumeration constants, macros, and temporary objects by role.

Read how Modern C explains constant →

Modern C, Third Edition

A named constant is a program constant given an identifier so code can refer to its meaning instead of repeating its value.

How it is used
Uses named constants to express meaning, prevent repeated special values, and improve maintenance and portability.
How deep it goes
Distinguishes enumeration constants, macros, compound literals, and C23 constexpr objects but defers their detailed mechanics.
Examples
Uses repeated array size 3, corvid_num, M_PI, false, true, SIZE_MAX, and fortytwo as naming examples.
What you can do after
Apply semantic naming to replace repeated values and select among C mechanisms for named or compile-time constants.

Read how Modern C, Third Edition explains constant →

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.