4 ms·
You can't talk about sensible naming without also talking about scope. When a variable is only in scope for five lines, it's perfectly reasonable to give it a
by ef4 15y ago
You can't talk about sensible naming without also talking about scope.
When a variable is only in scope for five lines, it's perfectly reasonable to give it a really short name.
- petdance 15y agoNobody said anything against really short names.
- pohl 15y agoYou don't consider "data".length() == 4 to be short?
- alex_c 15y agoNobody said anything against really short names, the article argues against non-descriptive variable names, whether short or long.
- evincarofautumn 15y agoIndeed, provided you know the problem domain, the most descriptive name (xs, x_rms) is almost always far shorter than the literal alternative (horizontal_positions, quadratic_mean_of_horizontal_positions).
- deleted 15y ago[deleted]
- Lockyy 15y agoWhy are you working under the assumption that that was his issue with the term data? Especially when he specifically described his problems with it.
- pohl 15y agoI'm not. Rather, I'm supporting the notion that as the relevant scope decreases, the weight of his objections to the variable name 'data' vanish and become dominated by the value of its brevity.
- mokus 15y agoThe same argument applies to non-descriptive names, and the main complaint about short names is that they are often not descriptive. I like to bring up the English language in this particular debate. "It", "he", and "she" are incredibly non-descriptive names, but each one of them is used many orders of magnitude more often than any "descriptive" name (other than maybe "I" or "you") and yet we don't hear rants about that. The reason is exactly what the original commenter pointed out - scope. Sometimes the word "it" is descriptive enough all by itself. Other times it isn't. It's a more subtle matter than "worst variable names".
- riffraff 15y ago> Sometimes the word "it" is descriptive enough all by itself. Other times it isn't. It's a more subtle matter than "worst variable names". I see what you did there.
- zeteo 15y agoAgreed, the best variable name is the shortest one that's still specific within its scope. A variable name of CustomerWhoHasPlacedTheMostOrdersOnThisDay is quite bad inside a three-line function, just as "public static customer" is terrible in a five thousand lines factory class that has no obvious relation with a specific customer.
- tjpick 15y agothe five thousand lines factory class is the real problem.
- jdietrich 15y agoMathematicians solve for x, not for $unknown_quantity.
- riffraff 15y agoOT, but I do believe one of the important reasons why many people considered math hard is one letter names. Optimizing for writing is not optimizing for reading.
- jekub 15y agoI have to fully agree with you: I hate when people use 'unknown_quantity' instead of a simple 'x' as a simple line become very long and hard to read with the important informations spread over a very large area. Having to frequently parse very long name who doesn't give more informations is very painful, and generally make the real information harder to understand.