2022 Developer Survey is open! Take survey.
31 votes
Accepted

Explaining access levels and visibility in OOP

Here's an analogy that I've used for several years, and that students seem to understand. It doesn't focus on the rules, but why we have public and private and protected. "Most of you know that I ...
user avatar
31 votes

Teaching students that printf() is not the same as return

I think this is a problem where the answer is partly in the prevention. I've observed many classes where printing is the method used to access the results of calculations for several weeks, both ...
user avatar
  • 1,955
30 votes

Analogy for teaching recursion

The Tower of Hanoi was one of the first ways that I encountered recursion. "The objective of the puzzle is to move the entire stack to another rod, obeying the following simple rules: Only one disk ...
user avatar
  • 1,256
27 votes
Accepted

How to respond to the two-handed approach to swapping

Don't overcomplicate things. Your first instinct, that the computer only has one hand, was the correct one. This is a regular problem that new teachers have, and it sometimes takes a few years of ...
user avatar
  • 31.2k
23 votes
Accepted

What are some good examples of using a stack data structure?

I once had to implement a limited undo function (undo changes to the current field, or addition/deletion of records). The lists of undo deltas (one for field changes and one for records) were stored ...
user avatar
22 votes

The Tao of TeaChing (Making Mistakes in Front of the Class)

If I catch it quickly and can easily explain the error, I use it as an example of failing up. "Ooops, look at me, here's my mistake, here's how I can learn from it." If students catch it, and I'm not ...
user avatar
  • 481
22 votes

How to respond to the two-handed approach to swapping

Re-evaluate what you think is "right", because you aren't but isn't right in computer science This is simply incorrect. Your student can create two variables called ...
user avatar
  • 1,072
20 votes

Analogy for teaching recursion

Can't claim it's my own idea but I can embellish it a little... Imagine you are entering a cinema. You sit down in a row but realise you had to sit in row 20. Being a lazy computer scientist in an ...
user avatar
18 votes

Teaching students that printf() is not the same as return

I think that this problem is pretty widespread, actually. I believe that it comes from a misunderstanding of the difference between what the program/computer can know/do and what the person operating ...
user avatar
  • 34.7k
16 votes

Analogy for teaching recursion

The image that I kept in my head when I was learning recursion was from Dr. Seuss:
user avatar
16 votes

What are some good examples of using a stack data structure?

A stack of trays in a cafeteria. I also like the pole of rings analogy. With the trays, you can pop (take a tray) and push (return it when you're done). You can see what the top tray (first item) is (...
user avatar
16 votes

How to respond to the two-handed approach to swapping

Your problem is that you tried to let your student "program" without establishing a language. Thus they were free to write their own "language" in which you can do two things at ...
user avatar
15 votes
Accepted

Analogy for teaching recursion

I like to use something that a student can connect with and something that they have to deal with regularly. You could choose any recursive everyday activity, but I like to choose revising an essay. ...
user avatar
  • 4,754
15 votes

What is a good analogy for the Object Oriented paradigm?

I've got to jump in here and talk about my experience having to help a former boss understand why the project he wanted to do wasn't possible in the time available. It came down to incompatible data ...
user avatar
15 votes

What are some good examples of using a stack data structure?

A rather interesting analogy is that of a firearms magazine. if we look at this picture: It is easy to see that bullets can be inserted from the top, and only the topmost bullet is accessible. Such ...
user avatar
  • 6,227
15 votes

What are some good examples of using a stack data structure?

The back button on a web browser is an excellent example of a stack implementation that is easily understood even by non-experts and easily demonstrated in a class. You can illustrate the stack in ...
user avatar
14 votes

What are some good examples of using a stack data structure?

Check whether a string of parentheses is balanced or not. For example, return True for these input strings: (()()) ([]{{}}[]) ...
user avatar
14 votes

The Tao of TeaChing (Making Mistakes in Front of the Class)

Mistakes are fine. We are human, we make mistakes. In fact, one of the worst things you can do in teaching is to never make a mistake and to always say exactly the right thing. This is pretty much ...
user avatar
  • 34.7k
13 votes

Explaining access levels and visibility in OOP

What my teachers used was the following example, which is pretty simple and most people understood. Your father orders a pizza. The delivery guy arrives and expects payment. The ...
user avatar
13 votes

A real world example for the divide and conquer method

Back around 1985, Susan Merritt created an Inverted Taxonomy of Sorting Algorithms. The idea is that to sort an array you have two phases, the split phase and the join phase. She divided the various ...
user avatar
  • 34.7k
12 votes

Teaching students that printf() is not the same as return

This is such a consistent trap that I ultimately created a worksheet to deal with it. At this point in my course, I have recently covered binary and hexadecimal, so I also use this worksheet as an ...
user avatar
  • 31.2k
11 votes

Explaining access levels and visibility in OOP

Ooh, this is one of my favorite lessons! I don't introduce package private and protected in the same lesson as private and public, because there are 3 principles that I want them to absorb that ...
user avatar
  • 31.2k
11 votes

What would be a good analogy for IP addresses and ports?

I used seats in the room. The classroom has an address. So, if someone wanted to come and talk to one of the students they would come down the hall and into my room. But, that only gets them to ...
user avatar
  • 3,029
11 votes
Accepted

Good, Motivating Examples for Algorithmic Complexity

I attack this problem with three "visits" over the course of two years with my students At our first brush with Complexity, I don't spend a ton of time motivating the study of it. I introduce the ...
user avatar
  • 31.2k
10 votes

What are some good examples of using a stack data structure?

I like the pez dispenser. Also the stack of papers (where the actual human interaction is never to take the top item but rather to take the second from the top. At some point you have to talk about ...
user avatar
10 votes
Accepted

The Tao of TeaChing (Making Mistakes in Front of the Class)

The teaching philosophy I came to as a young teacher (i.e. in my first year) was that I would ground myself in two qualities: passion and humility. (I've since added gratitude as an important third, ...
user avatar
  • 8,992
10 votes

What are some non-CS concepts that can be defined using BNF notation?

Going with real-world things which they should be familiar with are best, even if it is completely outside of education. As you have applied the tag for adult education, I'm going to presume it is ...
user avatar
9 votes

Analogy for teaching recursion

Recursion as a loop I'd present recursion as a form of a loop rather than being separate thing. Then, I'd show the students how to covert between flat form and recursive form, and discuss the pro's/...
user avatar
  • 897
9 votes

What is a good analogy for pass by value vs by reference?

Since I was tired of the easy IT examples which all revolved around sharing files and documents, I started using the following analogies to explain pass by value and by reference. My cat ("Mr ...
user avatar
  • 1,388
9 votes
Accepted

What would be a good analogy for IP addresses and ports?

I don't think the address metaphor is that off-the-mark -- real addresses are more segmented then IP addresses, true, but I don't know if that's really that much of a conceptual barrier. Regarding ...
user avatar
  • 3,995

Only top scored, non community-wiki answers of a minimum length are eligible