Home > empirical, psychology, Uncategorized > Ability to remember code improves with experience

Ability to remember code improves with experience

What mental abilities separate an expert from a beginner?

In the 1940s de Groot studied expertise in Chess. Players were shown a chess board containing various pieces and then asked to recall the locations of the pieces. When the location of the chess pieces was consistent with a likely game, experts significantly outperformed beginners in correct recall of piece location, but when the pieces were placed at random there was little difference in recall performance between experts and beginners. Also players having the rank of Master were able to reconstruct the positions almost perfectly after viewing the board for just 5 seconds; a recall performance that dropped off sharply with chess ranking.

The interpretation of these results (which have been duplicated in other areas) is that experts have learned how to process and organize information (in their field) as chunks, allowing them to meaningfully structure and interpret board positions; beginners don’t have this ability to organize information and are forced to remember individual pieces.

In 1981 McKeithen, Reitman, Rueter and Hirtle repeated this experiment, but this time using 31 lines of code and programmers of various skill levels. Subjects were given two minutes to study 31 lines of code, followed by three minutes to write (on a blank sheet of paper) all the code they could recall; this process was repeated five times (for the same code). The plot below shows the number of lines correctly recalled by experts (2,000+ hours programming experience), intermediates (just finished programming course) and beginners (just started programming course), left performance using ‘normal’ code and right is performance viewing code created by randomizing lines from ‘normal’ code; only the mean values in each category are available (code+data):

Number of lines of code correctly recalled by experts and beginners.

Experts start off remembering more than beginners and their performance improves faster with practice.

Compared to the Power law of practice (where experts should not get a lot better, but beginners should improve a lot), this technique is a much less time consuming way of telling if somebody is an expert or beginner; it also has the advantage of not requiring any application domain knowledge.

If you have 30 minutes to spare, why not test your ‘expertise’ on this code (the .c file, not the .R file that plotted the figure above). It’s 40 odd lines of C from the Linux kernel. I picked C because people who know C++, Java, PHP, etc should have no trouble using existing skills to remember it. What to do:

  1. You need five blank sheets of paper, a pen, a timer and a way of viewing/not viewing the code,
  2. view the code for 2 minutes,
  3. spend 3 minutes writing down what you remember on a clean sheet of paper,
  4. repeat until done 5 times.

Count how many lines you correctly wrote down for each iteration (let’s not get too fussed about exact indentation when comparing) and send these counts to me (derek at the primary domain used for this blog), plus some basic information on your experience (say years coding in language X, years in Y). It’s anonymous, so don’t include any identifying information.

I will wait a few weeks and then write up the data o this blog, as well as sharing the data.

Update: The first bug in the experiment has been reported. It takes longer than 3 minutes to write out all the code. Options are to stick with the 3 minutes or to spend more time writing. I will leave the choice up to you. In a test situation, maximum time is likely to be fixed, but if you have the time and want to find out how much you remember, go for it.

  1. David Barnes
    November 18th, 2016 at 10:06 | #1

    Derek,

    An interesting experiment, and I am minded to participate. However, I wonder why the requirement to reproduce on paper? I never code on paper and I don’t ask my student to sit written programming exams either. To me, that adds an artificial element to a timed reproduction.

  2. November 18th, 2016 at 12:50 | #2

    @David Barnes
    I suggested paper as it is the common media everybody has access to.

    I never turn away a volunteer; if you do answer using an editor, could you include that information with your data. It is possible that forcing people who have never written their code on paper, to use this approach, may change the results. Baddeley did an interesting memory experiment where divers remembered information under water and then either recalled it underwater or on land; there was a mode of recall effect.

  3. Luis Fernandez-Izquierdo
    November 21st, 2016 at 17:48 | #3

    Hi Derek, interesting research. Still I think that a true ‘expert’ benefits more from his/her higher level of abstraction when it comes to code than only memory by itself. Also interestingly this is not just correlated with time spent coding. Some people become experts in short period of time, other … never.

    Say someone has excellent memory and can remember a piece of code after seeing it once. That is no guarantee that he/she will be able to be highly productive with it, as, for example, recognizing novel scenarios where to apply it or to which category of logic it belongs to.

    On the other hand, say someone else sees a piece of code once, doesn’t remember the specifics, but was able to quickly identify it as a Scheduler (for example), i.e. something that schedule tasks with some parameters. This second ‘expert’ will be far more productive than the first one, even with his/her reduced memory capabilities.

    Obviously the above are two extremes and most people fit in between.

  1. No trackbacks yet.

A question to answer *