Skip to main content

Readable Code

beginner12 min readLesson 46 of 169

Names, small functions, no magic numbers, and comments that explain why.

Readable code is debuggable code. The rules are few and earned:

  • Names carry the design. retry_count beats n; is_valid_order(order) beats if o[2] == 1 and len(o) > 5.
  • Small functions. One screen, one job. If you need "and" to describe what a function does, it is two functions.
  • No magic numbers. if score >= 90: — what is 90? GRADE_A_CUTOFF = 90 documents itself.
  • Comments explain WHY, not what. # skip header row teaches; # add 1 repeats.
def letter_grade(score):
    if score >= GRADE_A_CUTOFF:
        return "A"
    ...

These habits cost seconds while writing and save hours while debugging — the compound interest of craftsmanship.