3 ms·
For math it's the other way around: long identifiers make things harder to read. When reading the code, the pattern of operators is what really matters; variabl
by athenot 10y ago
For math it's the other way around: long identifiers make things harder to read. When reading the code, the pattern of operators is what really matters; variables happen to be plugged into them.
For example, any person with a modicum of physics background will recognize the following as a kinetic energy calculation, even if I use random letters for the variables.
X = (a * b^2)/2
But if I throw that in a codebase for some web project, I would use fully explicit variable names.
This falls under the category of "know the audience for whom you are writing code".
- jamessb 10y agoFor example, any person with a modicum of physics background will recognize the following as a kinetic energy calculation, even if I use random letters for the variables. Someone with a physics background might assume that X is the kinetic energy of an object with mass a and velocity b. Or they might assume that X is the displacement of object after having acceleration a for a time b, having initially been at rest. The latter is perhaps more reasonable, since then the choice of two of three three variable names (x and a) is conventional. A reason why single-letter variable names are practical is that there are strong conventions about what particular variables might represent: eg. start of the roman alphabet is constants, end of the roman alphabet is variables, capital letters are matrices, many letters in the roman and Greek alphabets have one (or a few) common meanings.