Code is read far more often than it's written. You โ or a teammate โ will come back in 6 months and need to understand it. Clean code means writing for humans, not just computers.
Two programs can do the exact same thing, but one is a joy to read and the other is a headache. Let's learn the difference.
๐ท๏ธ Rule 1: Good names
Names should tell you what something is or does. Avoid x, data2, and tmp.
# ๐ต Mystery code
d = 86400
t = s / d
# ๐ Clear code
SECONDS_PER_DAY = 86400
days = total_seconds / SECONDS_PER_DAY
๐ก Naming guide
Variables & functions: snake_case
Constants: UPPER_CASE
Functions are verbs (calculate_total), variables are nouns (total_price).
๐ง Rule 2: Small functions that do one thing
A function should do one job. If you need "and" to describe it, split it up.