What Makes Code Good?
Readability and style: writing code that people can read, not just computers
- explain why "it works" is not enough,
- give things clear names,
- break a big job into small, tidy pieces,
- keep the structure neat and easy to follow.
1. Code is read by people
A computer does not care if your code is messy. It follows any correct steps. But humans read code too — to fix bugs, to add new parts, or to learn how it works. Most code is read many more times than it is written!
So "good code" means two things: it works, and it is easy to read and change. If code works but nobody can understand it, it is hard to fix later. Writing clearly is a kindness to the next reader.
2. Clear names
Every box (place to keep a value) and every helper should have a name that says what it is. A good name explains its job so you do not have to guess.
| Unclear name | Clear name |
|---|---|
| x | score |
| n | numberOfPlayers |
| doStuff | addPoints |
| a2 | playerName |
Think of names as labels on boxes. A box labelled "score" is easy to find. A box labelled "x" makes you open it just to remember what is inside.