Our brain interprets variables in two different fashions : semantic and symbolic. Semantic understanding means understanding the meaning of the variable’s name, where long and detailed names like “newCustomers” convey information in plain english and shorter names like “i” and “x” convey information through conventions. Symbolic understanding relies on recognizing the shape of the variable in several locations in code, and deducing from there its actual meaning—in itself, the name is not relevant, your brain just goes “hey, that’s the same variable“. Of course, there is some amount of semantic recognition to symbolic variables, usually because we understand the variable as being a symbol.
Mathematics make much use of symbolic recognition. After all, mathematicians do not write f(number) = 10 × number, they write f(x) = 10x and while one-letter variables do have some amount of semantics associated to them (i,j,k,m,n are integers, x,y,z are reals, p is a prime number, q and r are rationals, f,g,h are functions, t is often seen as time, d is a divisor, P is a predicate or a polynomial) this minimal amount of information is ridiculous when compared to the huge amounts of purely symbolic information one gathers from the use of the letter.
Symbolic recognition works better when the expression is small. In descending order of readability when you’re familiar with the language,
Mathematical notation:
ƒ : A → ∃n∈A. 2|n
Objective Caml:
let f(a) = List.exists (fun n -> n mod 2 = 0) a
C++:
bool f(const std::vector<int> &a) {
for(std::vector<int>::const_iterator it = a.begin(); it != a.end(); ++it)
if (*it % 2 == 0) return true;
return false;
}
I guess there are two things one can learn from this.
First, in a terse language, symbolic recognition works better, which in turns means the programs can be even more terse while retaining their understandability.
Second, don’t bother with long variable names in a two-line function if all the information present in the name can be readily and easily deduced from the two lines in the function.
Hi. I'm Victor Nicollet,
0 Responses to “Semantic & Symbolic”