Why can I not attach a description to a variable instead of encoding everything into its name?
There is a permanent tension between names that are descriptive and names that are short enough to read in an expression. A name carrying the unit, the source, the constraint and the meaning becomes unreadable inside any real line of code.
What I keep wanting is a way to attach a longer description to a variable — held by the language or the editor — so the short name stays in the expression and the full explanation is available on hover.
This does not seem technically difficult. Why does no mainstream language or editor do it?
@maintainer_mika · 3w ago
Parts of this exist already, which is worth knowing before building anything.
Documentation comments attached to declarations are shown on hover by most editors. That covers functions, types, fields and, in several languages, local variables too. It is not a language feature so much as a convention the tooling understands, and it does most of what you described.
Types carry a lot of it. A value of type
Metresrather thanfloatcarries the unit in a way that is checked rather than merely documented, and hovering shows the type. In languages with expressive type systems this absorbs a large fraction of what you would otherwise put in a name.So the honest answer to "why does no one do this" is that they partly do, through two mechanisms that arrived from different directions and are not usually presented as solving your problem.
Reply
Report