When you see a variable you can ask several questions:
- What is its scope?
- What is its lifetime?
- What is its type?
- What is its role?
HungarianNotation is one approach to variable naming that packs answers to several of these questions into a very few characters. However, it results in names that are an acquired taste, at best.
An analysis of the problem for Smalltalk reveals that several of the questions are answered by context.
- What is its scope? There are only three scopes in common use- global, which is used only for classes; instance; and method. As long as methods are short, you can quickly and correctly distinguish temps from instance variables by whether they are declared in the current method or not.
- What is its lifetime? In Smalltalk, this is the same question as scope.
- What is its type? In Smalltalk, this can be tricky, but the information is often easily gleaned from context. Formal parameters are an exception, so they are named with TypeSuggestingVariable?.
- What is its role? This leaves us with naming the variable exclusively after its role in the computation.