Hacker News new | ask | show | jobs
by dantotheman 5024 days 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").

3 comments

Generally, 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.
This 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.
Speaking of scope issues, you're missing a paren.
You 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.