3 ms·
It depends. Variable name length is mainly related to two things: * Scope the variable resides over * Generality of the variable If the scope is large (the v
by Peaker 15y ago
It depends. Variable name length is mainly related to two things:
* Scope the variable resides over
* Generality of the variable
If the scope is large (the variable is global and exposed to a lot of code), the variable name has to be longer, so that far away readers can make sense of it. A variable that scopes over 2 lines is allowed to be much shorter, especially if its definition is as clear or clearer than an arbitrary name.
As for the generality, if you write a function addEmployeeSalaries, of course that is a better name than some arbitrary short name (e.g: "addEm").
But when writing (very very) general code, it is hard to avoid situations where the variable denotes only structure. It is just too general to find a useful long (and specific) name.
For example, consider:
flip f x y = f y x
sequence :: Monad m => [m a] -> m [a]
Single-letter variable (and type variable) names, but considered perfectly good practice.