Identifier length and limited programmer memory

Identifier length and limited programmer memory
Dave Binkley, Dawn Laurie, Steve Maex, Christoper Morrell
Science of Computer Programming
Volume 74, Issue 7, 2009, Pages 430-445, ISSN 0167-6423

PDF

This paper presents results from a study of the interplay between programmer short-term memory limitations and entity names found within programs. The study is part of ongoing research into the impact that limited human memory resources have on program comprehension.

The “identifier length” in this particular paper is related to those long Java method invocations. They used Thread.currentThread().getName().substring(3) as one of the “identifiers” in their study.

This is a topic I love. I believe that variable and function names contribute a good deal to my ability to understand programs. I’ve always believed there was some balance between brevity and length of variable names that helped make a program read well.

This paper teases out variable name comprehension experimentally. They claim that identifiers of 3-5 letters help programmers remember, up to 8 letters of identifier length don’t matter, and above 8 letter names inhibit remembering. That is, long descriptive names like equalsIgnoreCase probably put undue burdens on people trying to understand the code. The investigators made a weird discovery: smaller number of syllables in longer words help programmers remember the names.

The other thing the investigators claim helps programmers remember identifiers is what they call “ties”. Ties are names or pieces of names that have already made it into programmers’ long term memory. I think the rest of us would say that “familiarity with the problem domain”. If you write code for the telecomm industry, it helps to know telcomm jargon.

The investigators make this recommendation:

Combined, these results reinforce past proposals advocating the use of limited, consistent, and systematic vocabulary in identifier names.

I don’t think this means using the dreaded Hungarian Notation. Practically speaking, Hungarian Notation involves CamelCase, which these investigators say “provides insufficient separation (e.g. the identifier equalsIgnoreCase is read as a single sixteen letter word).” They seem to prefer snake_case.

One amusing item they nonchalantly drop is that the “5±2” item capacity of short-term memory might just be 3±1.

I’m going to find one of the bibliography entries to see what “limited, consistent, and systematic vocabulary” means.

In the meantime, I’m going to try naming boolean variables according to this convention.