Magic Number
noun
say it: “MAJ-ik NUM-ber” /ˈmædʒɪk ˈnʌmbər/
A number written straight into code with no name, so readers have to guess what it means.
What is Magic Number?
Magic Number — A number written straight into code with no name, like 0.07, so the next reader has to guess what it is. Give it a name in a constant and the code explains itself, and changing it means changing one line.
decimal total = 50m * 1.07m; // what is 1.07?
const decimal SalesTaxRate = 0.07m;
decimal withTax = 50m * (1 + SalesTaxRate);
Console.WriteLine(withTax); // 53.50
In a sentence
- “The code reviewer flagged 1.07 as a magic number and asked me to name it SalesTaxRate.”
Level: Apprentice · More Software Development terms at this level
Updated