US Trends

why does the name of local variables start with an underscore discouraged?

Local variable names that start with an underscore are discouraged mainly because that pattern is widely used to signal “private” or “internal-use” attributes, especially in Python-style code.

Quick Scoop

In many languages and style guides (notably Python), a leading underscore has a conventional meaning:

  • It marks attributes or names that are considered “internal” to a module or class and not part of the public API.
  • Since Python has no enforced private variables, developers use _name to say “do not touch this from outside.”

When you use that same pattern for ordinary local variables, it can:

  • Blur the signal:
    • Readers may assume the name is some kind of private field or special internal variable when it is just a normal local.
  • Hurt readability in larger codebases:
    • Many teams treat a leading underscore as part of their interface contract (public vs. internal). Overusing _var for locals makes that convention noisy and less trustworthy.
  • Clash with existing conventions and tools:
    • Some linters, frameworks, and code generators treat leading underscores specially, so using them casually for locals can trigger confusing warnings or exceptions.

From a technical/runtime perspective, there is no performance penalty and the interpreter is not confused; the discouragement is about clarity, conventions, and maintainability , not correctness.

In short: using an underscore prefix is reserved by convention for “private-ish” or internal names, so using it for ordinary local variables is discouraged because it dilutes that meaning and makes code harder to reason about.

Information gathered from public forums or data available on the internet and portrayed here.