# Hard-Coding

> Typing a value right into the code. To change it, you must change the code.

**Field:** Software Development  
**Category:** Programming Concepts  
**Also known as:** Hard-Coded Value, Hardcoding, Hardcoded

## Think of it like

It is like writing a price on a toy in pen. To change it, you need a new toy.

## Definition

Hard-coding is writing a value straight into the code, where it is hard to change. A tax rate, a file path or a password typed into the source are all hard-coded. To change one, someone must edit the code and ship it again. The fix is to keep the value in a named constant, a settings file or the environment.

## Example

Jack typed the tax rate 0.2 into twelve places. When the rate changed, he had to find and fix all twelve.

## Example code

```python
tax = price * 0.2       # hard-coded
TAX_RATE = 0.2
tax = price * TAX_RATE  # named once
```

The first line hides the rate in a sum. The second names it once.

## Why it matters

Values change: prices, links, keys. When each one lives in one named place, a change is one edit.

## Common mistake

Hard-coding a password or API key. It ends up in Git, where anyone with the code can read it.

## Three principles

- **Baked in.** The value lives inside the logic.
- **Costly to change.** Each change means a code edit.
- **Name it once.** Use a constant or a settings file.

## Related terms

- [Constant](https://learn.benibix.com/term/development/constant)
- [Configuration File](https://learn.benibix.com/term/development/config-file)
- [Environment Variable](https://learn.benibix.com/term/infrastructure/environment-variable)
- [Clean Code](https://learn.benibix.com/term/development/clean-code)
- [Variable](https://learn.benibix.com/term/development/variable)

## Taught in

- [Variables and Assignment](https://learn.benibix.com/learn/development-concepts/variables-and-assignment): Programming Basics, 5/18

![Six small cards in two rows. Type conversion turns the text 42 into the number 42. Concatenation joins Hello and Emma. A tuple holds three values in fixed slots. An enum lists RED, AMBER and GREEN. A built-in function len counts five letters in hello. A hard-coded line has a tax rate of 0.2 written straight into the sum.](https://learn.benibix.com/diagrams/dev7-working-with-values.svg)

---

Source: https://learn.benibix.com/term/development/hard-coding
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-17
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
