Who Else Wants Better Short Term Memory?

In "Talent is Overrated", Geoff Colvin at one point discusses how superstars in many fields use the memory technique of "chunking" to boost their short term memory.

His simple example is the 13-letter word "lexicographer". To you and I (assuming you speak English and have a decent vocabulary), it is easy to remember. We don't have to remember 13 letters, we just remember the whole chunk. But when presented with "trgdpxhdewfwm" for 3 seconds, you probably can't remember more than half a dozen letters.

Another example is that chess masters can recall board positions after being shown a chess board with pieces on it for just a few seconds. They do this by chunking sets of pieces together -- almost like "words" -- whereas novices will try to remember individual pieces ("letters").

It struck me that programmers do the same thing when reading and writing code.

The coding standard helps us, by telling us where the chunks are and how to draw the boundaries between chunks.

If you have a coding standard.

And apply it consistently.

When you choose names at random, you destroy your short term memory. You become a crappy programmer, and you drag everyone around you down too.

Quick example in C. Assume you're writing a small module for checking environmental status.

BOOL isOverTemp();
BOOL isUnderTemp();
int GetCurTemperature();
BOOL env_isOverVoltage();
BOOL env_isUnderVoltage();

Anyone writing this pile of gibberish should be fired excommunicated.

Why?

For starters, I just wrote it, and I can't now remember which was camel case and which was underscored. Also: which one was abbreviated?

Before you object that this is a contrived example, two points: (1) yes, it is contrived, that's the point of an example, and (2) I have worked with far worse on an almost daily basis -- the example above is fairly tame.

On the other hand, if you know the coding standard has some simple rules -- and they are followed uniformly -- you can easily remember the function names.

  1. Initial 2-3 letter module prefix ("env" for this example).
  2. All functions are lowercase with underscores.
  3. No abbreviations.

Then we have:

BOOL env_is_over_temperature();
BOOL env_is_under_temperature();
int env_get_cur_temperature();
BOOL env_is_over_voltage();
BOOL env_is_under_voltage();

Now, when you're writing, reviewing, or maintaining code, you don't need to constantly refer to the header or documentation to get it right. A simple three-line coding standard just boosted your memory capacity by over 643%.

(In the interest of full disclosure: I made that number up.)

I realize that implementing even this simple three line standard is controversial because all the camel case folks are pulling out big sticks and the underscore people are grabbing rocks. To which I say: just flip a coin and enjoy the extra brain power. Adopt a three-line standard, follow it, and save the curly-brace debate for the next major coding standard revision.

Posted on 2009-11-12 by brian in process .
If you liked this, you should also read:

Comments

Around here we call that "StudlyCaps". Whatever you call it, it's considered decidedly immature.

Nathan Myers
2009-11-12 23:00:10

I guess that's one bit of California thinking I wouldn't mind migrating eastward. Honestly though, I care less about how you format it as long as you format it consistently.

Brian St. Pierre
2009-11-13 04:00:04
Comments on this post are closed. If you have something to share, please send me email.