DEV Community

Cover image for Supercharge Learning to Code with the Feynman Technique
rwparrish
rwparrish

Posted on • Edited on

Supercharge Learning to Code with the Feynman Technique

Intro

As a software engineering instructor, I've observed a common challenge among adult students transitioning to coding careers. Learning to code can be particularly challenging for adults due to ingrained learning habits, such as note-taking, memorization, and pattern-matching. Pattern matching won't deepen your understanding and can create false confidence. Memorizing syntax and methods will come naturally with practice, so it shouldn't be a priority either. In this piece, I advocate for adopting the Feynman Technique as a more effective approach to learning programming.

Richard Feynman was an American theoretical physicist known for his contributions to quantum mechanics, quantum electrodynamics, and particle physics. He was born on May 11, 1918, and passed away on February 15, 1988. Feynman made significant advancements in theoretical physics and won the Nobel Prize in Physics in 1965 for his work in quantum electrodynamics.

Apart from his scientific achievements, Feynman was also known for his exceptional ability to explain complex scientific concepts in simple terms - this brings us to the Feynman Technique for learning complex topics.

Outline of The Feynman Technique

So what is the Feynman Technique? It's actually quite a simple approach to learning that can be easily repeated:

  1. Choose a Concept and Explain It
  2. Teach It to a Child
  3. Identify Gaps in Understanding
  4. Review, Simplify, and Repeat

Let's walk through the process together using an example we're all very familiar with, tying our shoelaces.

1. Choose a Concept and Explain it:

Select a topic or concept you want to learn or understand better and explain it in simple terms. Use plain language and avoid jargon. Einstein said, "If you can't explain it in simple terms, you don't understand it well enough".

"Tying shoelaces is a way to secure your shoes to your feet so they don't fall off while you walk. It involves making loops with the laces and then tying them together in a knot."

2. Teach it to A Child:

Pretend you're teaching the concept to a child who has no prior knowledge of the subject. This could be a child, a friend, or even an inanimate object like a rubber ducky. Explain each step as you go along, making sure they understand the process. You may also want to demonstrate each step, especially in regard to coding.

"First, you take one lace and make a loop by crossing it over itself. Then, you take the other lace and wrap it around the loop. Finally, you tuck the second lace through the hole underneath the first loop and pull it tight to make a knot."

3. Identify Gaps in Understanding:

As you explain the concept, pay attention to areas where you struggle to explain or where your understanding is unclear. This helps identify gaps in your knowledge. Go back to your study materials (practice writing code and testing its behavior) and fill in these gaps. This step does require some humility and vulnerability - it's OK not to know everything!

If you struggle to explain how to create the loops or tie the knot, you may need to revisit those steps and break them down into smaller, more manageable parts.

4. Review, Simplify, and Repeat:

Review the concept and your explanations periodically to reinforce your understanding. If there are still areas you find difficult to explain, go back and review them again. Repetition helps solidify your understanding over time. Simplify complex ideas or terms until you can explain them in straightforward terms.

"To tie your shoelaces, first make a loop with one lace, then wrap the other lace around it, and finally tuck it through the hole and pull tight."

Applying The Feynman Technique to Coding

How can you apply this to coding? Let's take a look at an example and try to explain how the map() method in JavaScript works. To simplify the explanation I will use an analogy involving toy cars.

1. Choose a Concept and Explain it:

"Imagine you have a toy box filled with different toy cars, and you want to take each toy car, paint it a different color, and put it into a new box. This is similar to what the map method does with arrays in JavaScript."

2. Teach it to A Child:

In my view, the teaching step of the Feynman Technique should involve writing code and testing its behavior - not just a verbal explanation.

The Original Toy Box (Array): "You start with your original toy box, which contains all the toys (elements) you want to work with.":

const orignalToyBox = [
  {
    id: 1,
    brand: "Hot Wheels",
    model: "Mustang",
    color: "Red"
  },
  {
    id: 2,
    brand: "Matchbox",
    model: "Corvette",
    color: "Blue"
  },
  {
    id: 3,
    brand: "Maisto",
    model: "Lamborghini",
    color: "Yellow"
  },
  {
    id: 4,
    brand: "Tonka",
    model: "Pickup Truck",
    color: "Green"
  },
  {
    id: 5,
    brand: "Disney Cars",
    model: "Lightning McQueen",
    color: "Red"
  }
];
Enter fullscreen mode Exit fullscreen mode

The Painter Function (Callback Function): "Next, there is a painter who knows how to paint each toy a different color. This painter is like the callback function you provide to the map method. It takes each toy (element) from the original toy box and returns the painted version.":

function painterFunc(car) {
  car.color = "Orange"
  return car
}
Enter fullscreen mode Exit fullscreen mode

The New Toy Box (New Array): "As the painter finishes painting each toy, they put it into a new toy box. This new toy box represents the new array that the map method creates.":

let newToyBox
Enter fullscreen mode Exit fullscreen mode

Taking Each Toy and Painting It: "The map method goes through each toy (element) in the original toy box (array) and calls the painter function (callback function) on it.":

function painterFunc(car) {
  console.log(car) // check each car is passed to callback
  console.log(car.color) // check each car's color 
  car.color = "Orange" // reassigning each car's color
  console.log(car.) // check to see that the color is now Orange
  return car // give the car to the map method so it will be added to the newToyBox when map is finished iterating
}
Enter fullscreen mode Exit fullscreen mode

Returning the New Toy Box: "Once all the toys have been painted and placed into the new toy box, the map method returns this new box (new array) to you.":

let newToyBox = orignalToyBox.map(painterFunction)

// show the result in the console
console.log(newToyBox) // expected output:

[
  { id: 1, brand: 'Hot Wheels', model: 'Mustang', color: 'Orange' },
  { id: 2, brand: 'Matchbox', model: 'Corvette', color: 'Orange' },
  { id: 3, brand: 'Maisto', model: 'Lamborghini', color: 'Orange' },
  { id: 4, brand: 'Tonka', model: 'Pickup Truck', color: 'Orange' },
  { id: 5, brand: 'Disney Cars', model: 'Lightning McQueen', color: 'Orange'}
]
Enter fullscreen mode Exit fullscreen mode

We could try using different syntaxes for our callback function for extra practice with functions and conceptual reinforcement of how the map() method works:

const newToyBox = orignalToyBox.map(function painterFunc(car) {
  car.color = "Orange"
  return car
})

console.log(newToyBox)
Enter fullscreen mode Exit fullscreen mode
const newToyBox = orignalToyBox.map(function(car) {
  car.color = "Orange"
  return car
})

console.log(newToyBox)
Enter fullscreen mode Exit fullscreen mode
const newToyBox = orignalToyBox.map(car => {
  car.color = "Orange"
  return car
})

console.log(newToyBox)
Enter fullscreen mode Exit fullscreen mode

As you attempt to teach each step you will come to gaps in your understanding (Step 3. Identify Gaps in Understanding). With more practice writing code and explaining how it works aloud, our ability to teach will improve and therefore our understanding will deepen (Step 4. Review, Simplify, and Repeat).

Conclusion

If I could start coding again, I'd use the Feynman Technique more and ditch the need to take exhaustive notes and memorize syntax. All the information I needed is readily available online, like the MDN Web Docs for JavaScript. Instead, I'd hone my ability to ask the right questions and find answers online by referencing the well-maintained documentation. Applying the Feynman Technique will help you become good at asking the right questions because it is effective at helping you find gaps in your understanding.

There you have it. The next time you come up against a complex coding topic you're struggling to grasp, try the Feynman Technique. Stay curious, keep coding, and enjoy the never-ending learning journey. Thanks for reading.

Top comments (0)