4 ms·
I think the issue with single-letter variables goes deeper than it just being unreadable (although its that too for someone that isn't "used to it"). For examp
by dantotheman 14y ago
I think the issue with single-letter variables goes deeper than it just being unreadable (although its that too for someone that isn't "used to it").
For example there are issues with scope (what happens when I need a second or third "f" variable" and maintainability too (6 months from now I have to remember if "f" stands for "foo" or "file").
- Evbn 14y agoYou can look at the method signature that accepts or returns f. At worst case, you need an IDE with hover popups, or to open the functions doc page or source code.
- shasta 14y agoSpeaking of scope issues, you're missing a paren.
- lambda 14y agoGenerally, I try not to use single letter variable names in any scope that doesn't fit into a single screen in my editor. That way, I don't need to remember what "f" means, it's right there in front of me. And I shouldn't have too many variables in that scope, so conflicts aren't all that important; if I really do, I just start using multi-letter names again.
- viscanti 14y agoThis is a good heuristic. For me, single letter variables are almost always iterators in places where space is at a premium (i.e. one line list comprehensions in python). If I'm breaking a loop out over multiple lines (which is almost always the case), I prefer a longer, more informative variable name.