The Stack Overflow podcast is back! Listen to an interview with our new CEO.
95

Buffy's lovely answer shows well how two variables can refer to the same thing, but since we are in early cognitive development and working with Scratch, in which you can't pass parameters, and can't arrange for two different names to refer to the same instance/spawn, I wouldn't focus my efforts on that point yet. What matters is the idea of a holding place ...


37

My usual explanation is related to names; specifically names of people. People have names. The names are not the people, but can be used to refer to the people. Some people don't have any names at all. This is common just after birth at least, before the parents decide on a name. Names can be changed. A person can have a name for a while and then later ...


27

What about You have alot of values that you need to remember, so you put a label on each one (a little piece of paper to remind you what this value means) so you can find the value easily when you need it.


20

I actually cover this idea in my very first lesson in AP Computer Science, because I have found that students find the different uses of = to be confusing, indeed. I run a unit based on Tom Roger's unit, Java Ain't Algebra, and I also talk about it a little here. I do this right at the beginning because, if mutability is not made explicit, students do not ...


16

When I have taught this, I have said that = in programming is just a different thing to = in maths. It's unfortunate that someone (I say "some idiot", you might not want to use such language) decided to re-use = for assignment in programming, but now we are stuck with it. Programming, while it looks like maths, is more like a series of instructions. x=5 ...


14

The variable that children are most familiar with is score: whether in computer games, sports or board games, a child will almost certainly understand that a score is a value that is clearly not constant. Variables are abstract, but using familiar examples turns this into something easy to grasp. Once numeric variables are understood, you can extend the ...


11

If your students are coming from a math background, teach them that in most programming languages, all variables have a hidden subscript on them corresponding to a time/step-number (i.e. they're functions of time), and something like: $x = x^2$ really means something like: [Let] $x_{t+1} = x_t^2$ You might clarify that such a rule for $x_{t+1}$ only ...


11

Memory is a linear sequence of storage locations. Like a lined sheet of paper. Take a lined sheet of paper and choose a line. In the left margin, write a label. The variable is that label - it gives a name to a spot. Now look for the label and write something to the right of the margin. That is assignment.


9

I think this depends entirely on the programming language you use. Or maybe more accurately, you should choose a language that allows you to introduce the concepts in the order you want. I would use a language called Processing, which is built on top of Java and allows you to create visual, animated programs without any boilerplate code. I'd start with ...


9

I'm self-taught, but here are my thoughts. 0. Language I learned using a combination of Python (once I started to get more serious about programming, I actually don't remember how I stumbled across it) and JavaScript. Consequently, I have good indentation habits, and I haven't had to worry about problems you do have to worry about with some lower level ...


7

When and how should the differences be pointed out to students? When: As soon as you introduce one of those operators... On the "how" - I'd try to not beat around the bush, so to speak, but to point out straight away that only because we use the same symbol, they still have completely different meanings. Are there examples producing unexpected results ...


7

I'm going to explore an orthogonal concept that sheds light on the question at hand: What is a variable? In mathematics a variable is a representative for some value, a name. It may be a name for something we know or don't (abstraction comes in here). In an equation, the variable is sometimes called an "unknown". But that isn't precisely true. An equation ...


7

I just saw Buffy's answer so all credits to @Buffy and though I could simplify it with one word in a way that 9 year old me would have understood. (Although bear in mind I was also mucking around with Visual Basic 6 at 9 years old so this could also be very inaccurate & harder to grasp) A nickname. x = "the name of the program in scratch"; x is the ...


6

It might be a bit indirect but around that age I bootstrapped myself from fill in the blank math problems through basic algebra to more generalized variable use. eg I started with having been given problems like: 5 + __ = 9, what number goes in the blank? From there naming the blank to get to basic algebra problem: 5 + X = 9, solve for X. From ...


6

All of the below is meant to be thoughts/analogies/illustrations to help explain the difference (meant to be said to students) but in reality, this is all dependent on the level of your students. The expression x == x**2 in python is a "test" - is it true, or is it not? Much like when defining a set, you have $\{x|x>2\}$ (i.e., x is only included iff $x&...


6

In Structure and Interpretation of Computer Programs (SICP) (a book, video series, and university course), they do not cover variable mutation until around half way. They covered what seemed like everything I know before this. Including functions (not procedures) and object orientation. My thought are that these partial sequences makes sense: statements →...


6

If I remember correctly, Scratch has two kinds of variables - object-bound and global. When teaching my son about Scratch, at the time of introducing variables I told him he had been working with object variables/properties the whole time: the position x and y (and to a lesser extent the object sprite/appearance (not sure what it is called in the English ...


5

I don't teach CS in any official capacity but I have tutored a number of friends and colleagues on the basics. I find that differentiating the language I use when describing the different concepts helps a lot, for instance: Mathematical x=x*x = "X equals X squared" Assignment x=x*x = "X is made equal to X squared" Comparison x==x*x= "Test if X is equal to X ...


4

I've not tried the following, so I'm unable to vouch for their effectiveness, but if you're looking for suggestions: Avoid assigning variables directly (i.e. x = y) Hide the implementation in functions that have semantically clear names (e.g. x.Assign(y) ), although this assumes an object-oriented approach. Something like: x = Int.Create(y) uses assignment ...


4

I am not aware that cognitive modeling of memory structures in early programming education has been directly studied, so anything that I say here is entirely speculative. However, I suspect that the models themselves would somewhat depend on teacher presentation, and would otherwise be relatively stable. Take negative indexing as an example. A reasonable ...


4

My answer, for the past 20 years is OOP - but primarily as enabling composition, not inheritance. The notion of a class as a "bundle of behavior". Inheritance via interfaces, not classes, or the equivalent when not in a statically typed language. reference variables (no primitive data) Some design patterns to reinforce good OOP thinking (Strategy ...


4

I am of the school of thinking that starting at an abstract level causes too many students to consider computation as inscrutable magic. And that can lead to broken mental models and buggy ideas about how to code stuff. A 1970's vintage UC Berkeley Intro to Computing course (for non-EECS majors) used a cardboard computer with pencil-and-eraser-mutable ...


4

If this child plays Minecraft, you can try the following analogies: A variable is like a chest with a sign next to it. You can put stuff into a chest (assignment). This "stuff" in the chest is the value of the variable. A function is like a workbench, which transforms inputs (like wood) into the result (like wood planks in Minecraft). It is also helpful to ...


3

As you are teaching business people, not computer scientists (though what I say may also be true for teaching them). I would start on the more practical. Teach them stuff that is useful. Date, Currency (Don't use float types for currency, it will cost you your job, and someone a lot of money), Decimal (A float type with base 10 radix: it has less unexpected ...


3

I personally teach mutation almost immediately. However, I agree with Buffy that more difficult is not really the metric people are using to decide to teach mutation later. It is about giving certain key habits a chance to grow and develop before you get there. Most people find recursion naturally more difficult than a loop. There is no reason why this ...


3

I think that this is an interesting question, and one the textbooks often ignore or treat as unimportant. I've noticed it because I end up teaching Python, Java and C++ and have seen how my student's mental models lead to misunderstandings in their code. Here are the three things that seem the hardest for my students to understand: In Python, where ...


3

I would generalise this, because other symbols and terminology are also affected (">" or textual statements such as commands). Start by explaining that symbols and terms in each language have meanings specific to that language. They may overlap or have similarities, but never assume that just because a symbol or word has some meaning in one language or ...


3

I'm pretty sure that a general answer isn't possible here and it depends too much on at least (a) what the student has seen before, and (b) how the prof and other available materials describe things. In strong OOP languages (or with a strong OOP style in a weaker language), I can give students a mental model of computation that doesn't depend on a map to a ...


3

When introducing = and == in python, I refrain from reading them loud with a name that contains "equal" (or rather « égale » in French). Instead, I always read x = y as "x takes the value of y" (« x prend la valeur de y » which happens to be literally what the pseudo-language used in earlier classes mandates) and x == y "x has the same value as y" (« x a ...


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