Hacker News new | ask | show | jobs
by nl 3437 days ago
Ok, I accept you aren't trolling :)

I find it difficult to agree that using non-representative names for variables or functions improves understadability.

Notably, using something like x to represent a meaningful value means the brain has to hold the mapping between the two, which will decrease the number of useful pieces of information kept in short term memory[1].

The brain doesn't keep track of the number of characters in a variable name.

[1] http://www.psych.utoronto.ca/users/peterson/psy430s2001/Mill...

2 comments

So icsa[1] said something interesting on this point:

The issue, for me, is not readability but context. Even a word or two (e.g. cuts, begins, dims) helps greatly to establish the context of the code. Like having a map before hiking.

A comment can clearly provide that context without making the variable names long.

[1]: https://news.ycombinator.com/item?id=8747314

> The brain doesn't keep track of the number of characters in a variable name.

Surely you must appreciate that if we use too many characters the window will scroll?

long names are distracting. try using short names for variables where code requires scrolling and very short name for variables in short blocks of code (where you see the context without scrolling). something like 'idxLS' instead of 'indexOfLastSlash'. Or x+=totalsMst[i] instead of accumulatorOfTotalValues+=totalValuesFromMasterList[i] if this is the only line in a loop.

as your opponent has mentioned, context is the key. you operate with objects in your brain, and the faster the transition from code element to the brain object, the better you understand the code. long names make this lookup unnecessarily difficult.