🧩Hard-Coding
Also known as Hard-Coded Value, Hardcoding, Hardcoded
Typing a value right into the code. To change it, you must change the code.
Think of it like
It is like writing a price on a toy in pen. To change it, you need a new toy.
Example
Jack typed the tax rate 0.2 into twelve places. When the rate changed, he had to find and fix all twelve.
Why it matters
Values change: prices, links, keys. When each one lives in one named place, a change is one edit.
Definition
Example code
python
tax = price * 0.2 # hard-coded
TAX_RATE = 0.2
tax = price * TAX_RATE # named onceCommon mistake
Key takeaways
- 1Baked in. The value lives inside the logic.
- 2Costly to change. Each change means a code edit.
- 3Name it once. Use a constant or a settings file.