liveBook · Manning

Magic number

A magic number is an unexplained numeric literal embedded directly in code rather than represented by a descriptive name or explanation.

How 2 Manning books explain it

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.

Read how Learn Haskell by Example explains magic number →

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

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.