Magic number
A magic number is an unexplained numeric literal embedded directly in code rather than represented by a descriptive name or explanation.
Learn Haskell by Example
A magic number is a distinctive value in a file header that identifies the file format and sometimes its encoding variant.
- How it is used
- Uses header signatures to select PNM parsing and validate image data, then to categorize files before later processing.
- How deep it goes
- Builds parsers from fixed-string matching through remainder-carrying composition and branches header parsing on previously read markers.
- Examples
- Demonstrates PBM and PGM headers, P1–P6 parser cases, and byte signatures for BMP, PNG, JPEG, bzip2, and gzip.
- What you can do after
- Apply it via Data.ByteString and Haskell parsers to recognize supported file formats and reject inconsistent PNM data.
Learn AI-Assisted Python Programming, Second Edition
A magic number is an unexplained numeric literal embedded directly in code instead of being represented by a named parameter or variable.
- How it is used
- Keeps game behavior configurable by moving changeable numeric settings into parameters.
- How deep it goes
- Defines magic numbers and gives a review heuristic, but does not develop broader refactoring techniques.
- Examples
- Uses secret-code length and maximum guesses in a configurable guessing game.
- What you can do after
- Apply it by replacing changeable raw numbers with named parameters or variables.
Read how Learn AI-Assisted Python Programming, Second Edition explains magic number →
Related concepts
- enumalternative to · An enum is a type or language construct whose values are selected from a finite set of named alternatives, which may carry associated data.
- calc()addressed by · The CSS calc() function evaluates an arithmetic expression involving compatible CSS values and units to produce a computed value.
- inputaddressed by · An input is a value, information, or signal supplied to a system, computation, or interface for processing or to influence its behavior.
- maintainabilitycontrasts with · Maintainability is the degree to which software can be understood, modified, corrected, tested, repaired, or kept operational with reasonable effort over time.
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.

