Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Of course! I am talking about the names of local variables, not the names of externally visible functions or global variables.


There's a spectrum of how 'local' a variable is though. There's a big difference between a local variable whose uses span ~5 lines vs. ~30 lines. You're making a trade-off between repeating information (what the variable is) and forcing the reader to keep in their own (human) memory what each variable is for (or else forcing them to constantly go back and re-discover what the variable is for).

Go sometimes gets a lot of flak for its style here (partially because it's sometimes misapplied) but I think it works pretty well: it's fine to use a short non-descript variable name like `a` if its uses only span a few (~5-10) lines (or other certain special cases like `i`, `j` for loop indexes), otherwise use longer descriptive names.


This sounds more a problem about your total number of local variables than their names. If you have too many variables, using longer names is not going to help you as much as organizing your code differently.




Consider applying for YC's Fall 2026 batch! Applications are open till July 27.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: