Teaching Python

We're two middle school teachers learning and teaching Python

The Power of Metaphors in Learning


In education, teachers seek innovative ways to make abstract concepts more accessible to learners. One powerful tool is the use of metaphors. These allow students to engage with new ideas without needing to grasp every detail perfectly from the start.

Metaphors in Coding

In computer science classes, metaphors are invaluable for introducing abstract concepts to beginners. Consider the example of using a hamburger to explain if-elif-else statements in programming:

  • The top bun represents the "if" statement.
  • The patty stands for "elif."
  • The bottom bun symbolizes "else."

This analogy gives new coders a simple way to visualize conditional structure. However, this metaphor isn't perfect. Unlike a hamburger, where all components exist simultaneously, in programming, only one condition in an if-elif-else statement is executed at a time.

So, why do we use metaphors? And more importantly, why do they work?


Why Imperfection Leads to Growth

The magic of metaphors lies in how they engage our brain's natural learning process. Metaphors serve as shortcuts, reducing the mental load on new learners by making coding concepts more accessible. They offer a familiar starting point that helps students navigate complex syntax and new vocabulary. However, their real power emerges as learners progress and begin questioning the limitations of metaphors, which sparks critical thinking and knowledge acquisition.

As students advance in skills, metaphors eventually phase out. Students can recognize that simple metaphors like the hamburger metaphor do not fully explain conditionals and code. They realize that one condition is executed or additional options are available, leading to deeper concept analysis. This discrepancy between the metaphor and reality pushes students to think beyond the surface and engage more deeply with the actual code.

However, our brains are naturally wired to seek patterns and resolve inconsistencies. They work hard to reconcile simplified metaphors with more complex truths. This process strengthens understanding and retention, fostering a growth mindset. As students build their knowledge, they begin to see the limitations, develop critical thinking skills, and allow their brains to tackle more advanced concepts.

Imperfect metaphors play a dual role: they make abstract coding concepts accessible early on, and their limitations become a springboard for deeper learning and cognitive development.


Comparing Metaphors

Let's explore two common imperfect metaphors for conditionals: the fork-in-the-road and the hamburger method:
Fork in the Road

  • Benefits: This metaphor effectively illustrates decision-making in code—only one path occurs at a time, just like choosing a direction at a fork in the road. It conveys the mutual exclusivity of conditions, which leads to decision tree discussions and program flow.
  • Disadvantages: This metaphor does not give young coders a visual sense of structure for writing simple code. Sometimes, decision trees with multiple choices overwhelm young coders looking to implement their creative ideas into code. It is hard to show how all conditions fit together in a flow chart without complicating a simple program structure.

A common error, I found early on, is that students didn't understand decision trees, espeically in this problem in Tynker. A person with an option to turn left and right has only one decision. Using 'if left' AND 'if right' will confuse a person whose two hands are extended to turn. Coders must use an elif or else statement to complete. But kids would often be "laughed at" literally by the avatar in the program.

Hamburger

  • Benefits: The hamburger metaphor provides a structured visualization of if-elif-else statements, helping students see how conditions are connected while reinforcing the correct syntax. It's engaging, using a relatable concept that makes conditional logic less intimidating. Its simplicity aids in memorability, making it easier for beginners to recall how conditional sequences are laid out in the editor. Kids can look for the pickle: "If the pickle is under the top bun, take it out and put the bun back. Elif look under the patty, etc."

  • Disadvantages: This metaphor needs to be more accurate for advanced coders because it implies that all conditions are present; advanced coders quickly realize that this is an oversimplified metaphor and does not depict how conditionals execute in sequence.

These metaphors serve different purposes: the hamburger helps visualize the structure, while the fork-in-the-road better explains decision-making. The fitting metaphor depends on what aspect of conditionals you want to emphasize in your teaching and the level of your coders.


The Cognitive Power of Metaphors

Barbara Oakley, author of A Mind for Numbers and Learning How to Learn, uses metaphors to simplify abstract concepts. For instance, she compares the brain's focused and diffuse modes of thinking to spotlights and lanterns, helping learners understand the difference between the two modes of thinking. Oakley also uses an octopus metaphor to explain concepts of attention and working memory and 'metabolic vampires' that suck life from neurons. These creative uses of metaphors are fun and easy to remember, allowing your brain a tool to make learning accessible.

In line with Oakley's approach, metaphors act as "chunking" mechanisms that simplify complex information into manageable units. While they aren't precise, their strength lies in building an intuitive framework for learners. Students can refine and expand their knowledge beyond the metaphor's limitations as they advance their understanding of complex topics.

Other Coding Metaphors

Metaphors are everywhere in education and are extremely helpful in helping new coders grasp vital concepts. They lighten the complexities of code and give students an easy way to get started. As Oakley states in her books, metaphors make learning fun, and these "new tools open your mind to try or try again to learn concepts you thought were out of your reach." Let's look at a few more imperfect metaphors.

  • Variables as a Box: This metaphor helps students visualize variables as containers for storing values. However, it oversimplifies the dynamic nature of variables, which can hold complex data types and refer to memory locations rather than being fixed containers (Basu, 2008).

  • String as a Birthday Banner: A string is often compared to a banner, with each character as a flag or panel. While this helps explain sequence, it misses out on the flexibility of strings, such as slicing or concatenation.
  • List as a Train: Python lists are sometimes compared to trains, with each car representing an element. This metaphor helps visualize order but breaks down when considering operations like sorting or filtering. For example, two lists with the same items in different orders aren't equal (==), something the metaphor doesn't fully capture.

  • Function as a Recipe: The recipe metaphor illustrates how functions contain instructions to achieve an outcome and how inputs (arguments) alter the output, much like varying ingredients in a recipe. It simplifies the idea of reusing code and processing inputs. This metaphor oversimplifies functions by not capturing advanced features or side effects. Also, recipes typically produce a single result, which only partially reflects the flexibility and power of functions in programming.
  • Books for Functions: Think of a function like a book , with pages representing the process and logic inside. When you use a print statement, it's like writing a message on a sticky note and handing it to someone. The message is visible for all to see, but once it's passed along, it's not stored inside the book anymore. Now, when you use a return statement, it's a bit different. It’s like writing a note, tucking it inside the pages of the book, and closing it. The message is hidden but stored away for when it's needed later. It’s not immediately visible like print, but it's still there, ready to be accessed when you reopen the book.

Learning after the Metaphors

Moving beyond metaphors is integral to a coder's journey from novice to expert. While metaphors are invaluable tools for introducing complex concepts, they become limiting. This is where educators must step in, guiding students to recognize when a metaphor breaks down and encouraging critical analysis of those limitations. As students gain proficiency, educators should help students challenge initial metaphors and concepts and foster deeper technical understanding and critical thinking.

The key to moving past metaphors is viewing them as temporary learning aids, not permanent truths. As students evolve, they should also create and critique their own metaphors, encouraging metacognition. This process turns metaphors from crutches into springboards for exploring the more nuanced and flexible aspects of learning.


How to Create Effective Metaphors

When creating metaphors, follow these essential guidelines:

  • Start with relevance—select metaphors that resonate with your audience's daily experiences.
  • Simplicity is crucial; the metaphor should be easy to grasp and explain without complicating the concept.
  • While no metaphor is perfect, aim for accuracy in capturing the core aspects of the coding idea.
  • Extensibility is another asset, allowing the metaphor to cover more complex scenarios.
  • Memorable metaphors use vivid imagery that sticks with students.

Also, remember to avoid these common issues:

  • Overreliance on metaphors without transitioning to formal explanations can hinder deeper learning.
  • Avoid overgeneralizing; clearly communicate where the metaphor breaks down.
  • Avoid cultural insensitivity by selecting universally understandable analogies.

Tailoring metaphors to different age groups and learning styles is key. For younger learners, choose concrete, playful metaphors, while for teens, connect metaphors to their interests. Adults may benefit from real-world, workplace-based metaphors. Adjusting metaphors based on student feedback ensures better understanding and engagement across diverse groups.

Applying Imperfect Metaphors in Education: A Personal Perspective

In my teaching, metaphors are powerful tools for young, new coders, breaking down the barrier that coding is only for those who "get it." By giving students familiar analogies, abstract ideas become more accessible to recall. The hamburger metaphor for if-elif-else statements helps students grasp structure, but they soon realize only one "layer" is executed, sparking discussions about flow. Similarly, the variable-as-a-box metaphor helps initially but later encourages deeper conversations about memory and data types.

Metaphors don't need to be perfect to foster critical thinking. They act as cognitive bridges, making coding accessible while encouraging exploration and deeper understanding. These tools open coding to everyone, showing that learning isn't about mastering a perfect concept but about using the flaws in a metaphor to dig deeper into the mechanics of programming. By embracing these imperfections, we teach coding and promote critical thinking and adaptability, preparing students to advance into the complex world of computing.


Resource

Basu, Shrutarshi. "Variables Are Not Boxes." Bytebaker, 5 Dec. 2008, https://bytebaker.wordpress.com/2008/12/05/variables-are-not-boxes/.

Haglund, J. "Good Use of a 'Bad' Metaphor." Science & Education, vol. 26, no. 2, 2017, pp. 205-214, https://doi.org/10.1007/s11191-017-9892-4.

Oakley, B., & Sejnowski, T. J. (2014). A Mind for Numbers: How to Excel at Math and Science (Even If You Flunked Algebra). TarcherPerigee.

Oakley, B., & Sejnowski, T. J. (2018). Learning How to Learn: How to Succeed in School Without Spending All Your Time Studying; A Guide for Kids and Teens. TarcherPerigee.

Samek, Miro. "Patterns of Thinking: Metaphors in Programming." EmbeddedRelated, 14 May 2022, https://www.embeddedrelated.com/showarticle/1451.php.

Videla, Alvaro. "Metaphors We Compute By." Communications of the ACM, 1 Oct. 2017, https://cacm.acm.org/practice/metaphors-we-compute-by/.