3 ms·
> "x=x+1" must be especially confusing to high-school kids I like immutability as much as the next programmer, probably more. But the idea that changing the
by sevensor 10y ago
> "x=x+1" must be especially confusing to high-school kids
I like immutability as much as the next programmer, probably more. But the idea that changing the value of a variable in memory is confusing to high-school kids gets repeated way too often with way too little evidence. X isn't the x from algebra, x is your bank account balance. That it changes at payday is not a hard analogy to understand. I have yet to meet the high-school kid who thinks this says that 1=0.
Now, like the rest of us, high-school kids can get tripped up by assignment and its consequences. Functional programming offers us great tools to deal with that. But the 1=0 argument is not credible to your average procedural programmer who's been doing assignment since the age of fourteen, and is in full command of basic algebra. A much better argument would be that Haskell lets you take advantage of algebra as an analogy, and Python doesn't unless you're unusually disciplined.
Edit: removed a word for grammar.
- willtim 10y agoI never said mutating a variable is confusing. I said repurposing the equality operator is potentially confusing, especially for children. Pascal used ":=" to mean assignment, long before Python existed.
- dragonwriter 10y agoBASIC used "=" for both assignment and equality tests long before Pascal existed and was more popular for teaching the youngest students even when Pascal was available, so I find the idea that the use of "=" for assignment is some kind of barrier that high school kids (or younger, even) are going to have a lot of problems with just as implausible as the idea that imperative mutation is such a problem.
- willtim 10y agoIt was before my time, but ALGOL used ":=" long before BASIC existed. The point is that academics have repeatedly not used "=" for assignment for successive new languages over many decades. Clearly they care, even if you do not.
- rwallace 10y agoWell yes, it's clear that repurposing '=' for assignment confuses or at least annoys many academics, no disputing that. But your earlier claim was that it confuses children, which it certainly does not. (Source: it didn't bother me in the slightest when I was learning Basic at age 11, or any of the other children I talked to about it.)
- willtim 10y agoYou have your personal annecdotes and I have my own. We will have to agree to disagree.