How the power of analogies can help us learn complex coding concepts
We’ve all been in a conversation where we attempt to explain a concept to someone unfamiliar with our field. What do we do? We relate the concept to something that they might be able to readily grasp, the more general the better. What we’ve just done is create an analogy that simplifies our process of understanding. We already understand concept A, therefore connecting it to a new concept, B, is much more intuitive.
It can be daunting to learn concepts in a programming language that seem to use made up words to describe functionality and ideas. The best way that I’ve found to understand some of these concepts and begin to apply them is by using stories and ideas from outside the computer science world that everyone can relate to. This gives our brains an immediate reference we can connect to our new knowledge.
One example that most people learning an Object Oriented language will be familiar with is of course the class. What is a class? It’s a way of translating real world things into a data structure to store information. How do we start understanding this relatively abstract concept? Let’s look at an example in JavaScript that will illustrate how we use classes to build models of our reality.
We’ll start with a book. A book has certain attributes that are common to all books right? It has a title, an author, a publisher and maybe we also want to model whether the book is being read, with a way to change that status.
class Book {
constructor(title, author, publisher){
this.title = title;
this.author = author;
this.publisher = publisher;
this.reading = false;
}
read() {
this.reading = true;
console.log(this.reading);
}
done() {
this.reading = false;
console.log(this.reading);
}
}
// A new instance of this Book class is created
let aBook = new Book(‘The Art of Learning’, ‘Joshua Waitzkin’, ‘Free Press’);
// Let’s start reading!
aBook.read(); // This will print out true now!
This is just one way that we can take complex computer science concepts and translate them into understandable examples. Let’s take a look at some other data structures:
A Stack is a data structure that allows you to add on and remove from the same end of a list. An analogy? How about a stack of pancakes, you always eat the last pancake you put on the stack right? So that is the core attribute of the stack: Last In, First Out. We abbreviate that to LIFO.
A Queue is another data structure but this one adds new items onto the end and removes them from the front of the list. An analogy is a line at the grocery store. The first person served is the first person in the line. If you just entered the queue you have to let everyone in front of you go first. This breaks down as: First In, First Out or FIFO!
Maybe you’ve heard the phrase: “It’s like riding a bicycle”? A classic example of an analogy, but what if you’ve never ridden a bicycle? There is a side to analogies that you should be wary of: the person your teaching must understand the analogous concept if they have any hope of understanding the new one. If I told you it tastes just like alligator you probably have no references of value that allow you to understand. Now switch the reference to chicken and you immediately know the flavor and feel of the food. Keep that in mind when building out your own links between subjects. Look for common experiences that you think will resonate with lots of learners. The more outlandish the imagery the better people will remember them!
If you are interested in learning more about the science behind why analogies are so powerful check out wikipedia.
Also if you have any analogies you love to use to explain tough concepts I would love to hear about them!
Below are some resources and interesting examples I’ve found that use analogies to help break down important concepts:
codeanalogies
Redux donuts
React Router Switchboard
Promises vs Callbacks in JavaSctipt
Maggie Appleton’s Illustrations of Web Development Concepts
Top comments (0)