How high school students start thinking about code
computinged.wordpress.com
computinged.wordpress.com
In mathematics, equality is symmetric (a=b is the same as b=a).
In programming, variable assignment is asymmetric (a=b is not the same as b=a).
Some programming languages recognize this but get the change wrong by changing the equality operator to == or === and always preferring assignment to be =. Some get it right, e.g., := as assignment.
e.g.
a <- [2] …
gives a the value of 2, unwrapping the List monad (only works if the return value of the function is a List of some kind).
The above could also be written:
[2] >> (\a -> …)
It’s been a while since I’ve done much with haskell, so forgive me if I’ve mis-remembered something.
I think I’ll live with 1 less karma ;)
a <- [2]
binds a to 2, rather than [2], makes no sense.
edit:
a better example (because it is more useful) would be:
a <- Just 2
which, again, binds a to 2, unwrapping the Maybe monad in the process. (I forget what happens if you try to do a <- Nothing)
(Comparison, which is symmetric, is "==".)
This is a tradeoff of one hard day in your teens ("But but but equals should work both ways! head explodes") and thirty seconds every time you pick up a new language ("Assignment operator is equals? Got it.") versus typing more several dozen or hundred times a day every day for the rest of your professional life.
"Let <boolean expression>" means that the world gets set up so that the boolean expression is true.
Examples:
Let x=4
Let epsilon>0
Let a in A
There's very interesting work on providing an iteration construct like this in a programming language.
(let ((x 5)
(y 10))
(+ x y))
=> 15See if there is a language that is further upstream than the rest, and also see if there is a language that is such a paradigm shift from the rest, and perhaps even from typical human-thought patterns, that many people from every group struggle to learn it. For those who don't, see if you can discover what is different about how they reason their way through programming.
Or perhaps find the language that everyone just gets once they've been exposed to one or more other languages. See if it really is the easiest, and more sparsely featured of the bunch, or if it just does a remarkably good job of unifying the concepts from all the others.
Just a couple of thoughts as I read your comment. :-)
For me, this is Haskell. Trying to write any decently large program (say, a Super Mario clone) causes brain hemorrhage.
I've also met people who learned Haskell as a first programming language (common in UK unis). A lot of them wind up being crappy C++/Java/Python programmers, because they keep waving their arms and expecting magic to happen like it does in Haskell.
Indeed, I learned Python and Haskell simultaneously during a seriously nerdy week (the gf. was away :) and my Python codes came out with a bloody lambda on every other line! Then I realized I was trying to re-implement laziness, but obviously Python lambdas are not lazy at all (that's right - stuff gets evaluated when you define the lambda).
Programming mostly in Haskell, I could say the same (brain hemorrhage) about imperative programming languages. There are just so damn (unnecessarily) hard to program in.
My nephews kept thinking of functions, operators, and special forms (conditionals and iteration) as "objects". They wanted to put "title", "value" and "callback" on the "wrong" objects. For example, they could bind a callback to a button and have it popup when it was clicked; they want to attach a similar callback to a block of code and have it fired when the block was executed (a trivial problem to fix; just call your callback from the body of the code block, but they wanted to use call-back syntax.)
I am sure they would have loved Squeak, but I didn't have the time to learn it on time; my previous experience with Smalltalk has been brief, mainly with GST and theoretic uses of Self.
Kids are a tougher crowd to please than programmers with some "training", because children have not yet accepted whatever limitations imposed at us by "industry". They want the Ideal.
Which is what everyone should be demanding. What's the point of software that you can't program yourself?
He understood that there was a relationship between the array and the counter variable, but he took the relationship to far. He thought that the counter variable needed to represent the element of the array, and so he was assigning the value of the particular element in the array to the counter variable. In his mind, the counter variable didn't just provide the element number to look for; it was the element he was looking for, or at least it needed to become so.
Both this, and the color example provided by the author, demonstrate how many implied relationships we depend on within the programs we write, and how many people believe that those relationships to be explicitly stated or else the compiler won't understand what we mean.
I don't think I was able to get my friend to really understand what was going on and why we couldn't just 'tell' the computer to 'relate' these two things for us. It was a level of such naive concreteness that his mind just fought against descending to. I wonder how someone might educate people in thinking at this level? The optimist in me says it might be possible; the pessimist suggests that it might be in the same realm as trying to get people to understand pointers and recursion, which enough people I've read suggest is extremely hard for some (many?) people to understand.
= vs == strikes again.
a = 3
b = 4
c = ?
Granted, this is one person's experience, but I never recall a variable's value being presented as 3 = aPossibly more important, you would never see:
a = 3
a = 4
Begs the question: which is it, 3 or 4? Or does 3 = 4 too? Just a reminder that the operators really are equality, not assignment.Once you get used to it you stop thinking about it, but it's important to realize that this concept isn't as intuitive as it may appear.
Oh, and you didn't ever use the store arrow key (STO->) on your TI-83 to store a value? With this operation the variable goes on the right of the expression, not the left.
I remember coding them directly with the keyboard on the calculator. I wrote all kinds of things, things to help me solve things, solve equations, geometry solvers, games. It was a blast, and I think that's what got me interested in programming.
Thanks TI! Maybe Middle Schools should work on developing an introductory programming curriculum to introduce kinds to the idea of programming. It's probably more important then most things middle schoolers are learning, especially considering I probably spent so much of my time in math class programming my calculator.
(OT: I can also write mirror-text at my natural hand-writing pace, and often get the order of drawing individual glyphs "wrong"; I might, for example, make a dot first then a vertical bar to wite an 'i'. The occassional "russian" backward or upside down letter creeps in when I am tired, etc.)