3 ms·
I agree. It's not a mental tax to read a word we recognize. It's not like we have to sound it out letter by letter, we recognize its form at a glance. It's more
by elishacook 10y ago
I agree. It's not a mental tax to read a word we recognize. It's not like we have to sound it out letter by letter, we recognize its form at a glance. It's more taxing to maintain a mapping for an inherently meaningless single character.
Although there are some single characters that do have meaning due to long time convention such as 'i'.
- chriswarbo 10y agoWhat about variables which are inherently "meaningless", i.e. they're only given a name in order to distinguish them from each other? For example: function flip(func) { return function(x, y) { return func(y, x); }; } function compose(func1, func2) { return function(x) { return func1(func2(x)); }; } Code like this is completely generic; we know absolutely nothing about `x`, `y`, etc. other than they're distinct arguments; we don't even know their type (they're "parametrically polymorphic"). Would it be better to call them something like `arg`, or `arg1` and `arg2`? The fact they're arguments is obvious, so that would be just as redundant as something like `int int1 = ...`. This kind of generic "plumbing" appears all the time when using a functional style, where our function's job is to take in a bunch of values and combine them in some way, without caring what they are.
- kazinator 10y agoIf the variables have no meaning other than argument placeholders in a transformation between functions, then they must not be given descriptive names that falsely hint at some deeper meaning.
- vanderZwan 10y agoYou answered your own question: such abstract (not meaningless) variables make sense when the code is completely generic. Most code however is somewhere between generic and specific, literal values, and variable names should represent that semantically. Also, I would even argue that x and y are not meaningless in this context. There's a reason you didn't write: function flip(gnarf) { return function(t, m) { return gnarf(m, t); }; } function compose(bip, boop) { return function(blep) { return bip(boop(blep)); }; } The sequences {a, b, c}, and {i, j, k}, {m, n}, {p, q}, {x, y, z} are all well-established "abstract" variable names that most of us remember from high school algebra, and all have different baggage and expectations: - a, b, and c tend to be generic labels for things, not numbers - i, j, and k are used for indices and tend to be natural numbers (or more rarely for complex numbers/quaternions, where they are floats) - m and n are used in matrices and also are used for natural numbers - in maths, p and q are often fractions - x, y, and z tend to represent coordinate systems and/or floating numbers We can combine this to create variable sequences, with subtly different meanings. For example: compare (x1, y1), (x2, y2) with (xa, ya), (xb, yb). To me, if I see foo(x1, y1, x2, y2) that implies either top left, bottom right in an axis aligned bounding box, or perhaps the first point and the second point of a line or vector, or some other situation where the two points are somehow connected in one object or shape. Using (xa,ya) and (xb, yb) however suggests I'm dealing with two distinct points.
- jdmichal 10y agoIt irrationally bothers me that you didn't use `f` and `g` for your composition example, as that's the common mathematical representation. function compose(f, g) { return function (x) { return f(g(x)); }; }