Course contentsShow
← Software Engineering
Lesson 366 of 1,93311. Code Quality and ReadabilityFree lesson

Avoiding Meaningless and Generic Names

Recognizing and replacing vague names like 'data', 'info', 'temp', and single letters with specific alternatives.

Avoiding Meaningless and Generic Names

You'll learn how vague, generic variable names obscure your code's intent and how to replace them with meaningful alternatives.

The Problem with Generic Names

Names like data, info, temp, x, i (outside loops), or result tell you nothing about what the variable actually represents. They're placeholders that force readers to mentally decode your code, wasting precious mental energy.

Think of it like labeling kitchen containers. A jar marked "stuff" is useless—you have to open it to know if it contains flour, sugar, or coffee. But "wholeWheatFlour" tells you exactly what's inside at a glance.

Common Offenders and Better Alternatives

  • data → What kind of data? Try customerRecord, sensorReading, or jsonPayload
  • info → Same problem. Use userProfile, errorDetails, or configSettings
  • temp → Temporary for what purpose? Replace with oldPassword, swapValue, or previousIndex
  • Single letters (outside loops) → x, y, z are fine for coordinates, but otherwise use distance, velocity, userName
  • result → Result of what? Try isValid, customerCount, or totalPrice

The Exception

Single letters like i, j, k are acceptable for simple loop counters within a tiny scope, because their purpose is immediately clear from context. But even here, index or row and col are often clearer.

Making the Shift

When you write a generic name, pause and ask: "What does this actually represent?" The answer is your better name. If you can't answer clearly, your design might need refinement.

Key Takeaway: Meaningless names like data, temp, and single letters hide intent—replace them with specific names that reveal exactly what the variable represents and how it's used.