← Back to all articles
Ilya Petrov

A Few Notes on Naming

Names are part of the interface: they shape how quickly a reader can understand a system.

codewritingcraft

Good names reduce the amount of code a reader must hold in their head. They describe the thing as it is used, not as it happened to be implemented.

Prefer intention

Compare:

const x = posts.filter((item) => !item.data.draft);
const publishedPosts = posts.filter((post) => !post.data.draft);

The second version does not need a comment. It gives the reader a useful assumption immediately.

Names should survive change

Names based on temporary details age badly:

  • newPosts becomes confusing after a refresh;
  • blueButton breaks when the design changes;
  • data says nothing about its shape;
  • handleIt hides the action.
Weak Clearer
data articleMetadata
run generatePreview
list publishedArticles
tmp normalizedSlug

Naming is a small design task performed inside the code. Give it the same care you give labels in the interface.