Learn a programming language with flashcards


February 16, 2020

It can be frustrating to switch languages or stacks. While you're learning, you feel inefficient and might compare yourself unfavourably to more experienced developers. Fortunately, there is a solution: use flashcards to speed up the initial stages of learning! Read on to find out efficient techniques for creating flashcards specifically for learning programming languages.

How do flashcards work?

You have likely encountered flashcards as a learning aid for memorising vocabulary of a foreign language. A traditional flashcard is a piece of paper, one side of which (the front) contains a prompt, or a question; the other side (the back) contains the answer. A collection of flashcards is called a deck.

When reviewing a deck, you pick up a flashcard, read its front, and think of the answer. Then, you check whether you have answered it correctly by flipping the flashcard and reading its back.

While you can review the whole deck at once, it is more efficient to do so using a spaced repetition system (SRS). The more often you answer a question correctly, the less often you review the flashcard.

Since storing flashcards by next date of review is a bit fiddly, people have created multiple flashcard automation programs. I would recommend starting with Anki. It is the most configurable flashcard program I've used, and it has a large repository of free decks to download. It also stands out from competitors because of a transparent, user-friendly funding model (desktop and web free, mobile pay-once-yours-forever; no SaaS.)

OK, but DO flashcards actually work?

Anecdotally, yes :)

I used two flashcard decks as part of my recent job interview preparation process. One of those was a publicly-available Python Anki deck. The other was a deck I created myself, consisting of basic computer science facts and algorithms. I don't use Python for day to day development, but (after solving some hackerrank problems) I felt comfortable using it for whiteboarding problems. Given that recall ability deteriorates in stressful situations, it felt like flashcards improved my interview performance.

Before writing this article I also ran an informal poll on Twitter. Nearly 20% of people who responded have previously used flashcards to learn a programming language. This seems high enough to prove the usefulness of the technique, and low enough that you may still gain a competitive advantage over people who don't use them.

What can you learn using flashcards?

Flashcards can be used to:

  • memorise associations between two concepts
  • memorise short sequences of concepts, where order is important
  • prompt yourself with topics for theory recall

In the context of programming languages, you can use flashcards to learn:

  • language keywords
  • language syntax
  • core library functions
  • user library functions
  • edge cases
  • language idioms

What can't you learn using flashcards?

Flashcards train your ability to recall information after receiving a cue. Learning a programming language with flashcards will help you read and understand code better. However, you will still need to practice writing the language in some other way.

How to build your own deck

While you might want to start with an existing deck, I would encourage you to eventually build your own. Building a flashcard deck, like taking notes, speeds up your learning process. Your brain regularly forgets unimportant information. By carefully considering whether a piece of information is worth learning, you make it more salient, and thus less forgettable!

Basic flashcards

Basic flashcards train visual recognition of a word or a phrase.

Use basic flashcards to learn language keywords and library functions.

Basic flashcard: front Basic flashcard: back

Cloze deletion

A cloze deletion test is a fancy term for "fill in the blanks". A cloze card looks like this:

Cloze flashcard: front Cloze flashcard: back

A single flashcard can have many "blanks", although in Anki only ever hides one of them at a time.

"Cloze cards" are well suited to learning groups of related concepts, or sequences of steps. You can also use them for an unordered list of things, if you introduce an artificial order to this list.

Trivia: the word "cloze" is derived from "closure". It comes from the law of closure in Gestalt psychology: a theory that humans tend to remember objects as complete and they automatically fill out the missing gaps.

Flashcard prompts

Once you've gotten fluent in recognising library functions, you will need to learn how to use them in context. Prepare flashcards with short code samples to demonstrate both expected use of a function, and how it reacts to edge cases. If using Anki, install Syntax Highlighting for Code Anki add-on to create more engaging flashcards.

Examples

Basic flashcard: keyword

FrontBack
if

Evaluates test condition, executes either then block (if the condition is true) or second block (if false)

Basic flashcard: library function

FrontBack
(take-while pred coll)

Returns a lazy sequence of successive items from coll while (pred item) returns logical true. pred must be free of side-effects

Code sample: core library function, simple usecase

FrontBack
What does this expression evaluate to?
(filter even? [1,2,3,4])

A lazy sequence (2,4)

Code sample: language idiom

FrontBack
What does this expression evaluate to?
(let [coll '()] (if (seq coll) "yes" "no"))

"no"

Code sample: core library function, edge case

FrontBack
What does this expression evaluate to?
(first [])

nil

Cloze deletion: syntax

[while][(test)][{
    // code
}]

The above card will produce the following three test cases:

[...](test) {
    // code
}
while[...] {
    // code
}
while(test) [...]

Cloze deletion: a sequence of steps

Pre-order depth-first tree traversal.

Given a tree, and an action to perform on a tree node:

1 [initialise a stack with tree root]
2 [take the first node from the stack]
3 [perform an action on the node]
4 [push all children of the node onto the stack]
5 [if the stack is empty, finish; otherwise, goto 2]

Cloze deletion: unordered list

Edge cases for a string argument (outer to inner):

1 [String length: is the string empty?]
2 [Allowed character classes: alpha, alnum, punct, space?]
3 [Encoding: UTF or ASCII?]
4 [Null terminated?]
Tags: programming-languages grok mind