The Weight of Naming Things

There are two hard things in computer science: cache invalidation, naming things, and off-by-one errors. The naming one doesn’t get enough respect.

Why Names Matter

A variable called data tells you nothing. A variable called unprocessedUserSubmissions tells you everything. The time you spend naming things well is paid back every time someone reads your code — including future you, who will have forgotten everything.

The Naming Spectrum

  • x — You’re either doing math or you’ve given up

  • temp — You promised yourself you’d rename it

  • handleClick — What does it handle? Why does it click?

  • submitPaymentAndUpdateInventory — Now we’re talking

Functions

Function names should be verbs. If your function name doesn’t contain a verb, it’s probably lying about what it does. userValidation is a noun pretending to be a function. validateUser is honest.

The Rename Refactor

Renaming a function across a codebase takes five minutes and improves clarity for years. It’s the highest ROI refactor available. Do it more often.

The old maps named the deep places. Not for decoration — so that sailors who came after would know where they were.

— JP, from the void.

Reply

Avatar

or to participate

Keep Reading