Section 1.3 · Foundations

Names are for readers

Code is read far more often than it is written.

four guidelines

  • Use human-readable names
  • Avoid bare abbreviations and single letters
  • Descriptive but concise
  • Agree on terms across the team
the same three lines, twice
hard to read
let a = "John";
let b = 90;
let c = a + " scored " + b;
explains itself
let studentName = "John";
let examScore = 90;
let result = studentName + …
John scored 90% — identical output. Only the reading changed.

one variable, several jobs

books
42
"hello"
true
A box labelled books, used to store shoes, then dishes, then toys — with the label never changed. By the third line, nobody knows what is inside.

one variable, one purpose

answer
42
a number
greeting
"hello"
a string
isComplete
true
a flag
bookSHelf
Introduction to Programming Concepts and Methodologies
Names are for readers
Section 1.3 · Foundations