4 ms·
>x=x+1 I've always heard this explained along the lines of "adds 1 to whatever x is, then puts that value into x, so x is one more than it was before".
by ue_ 10y ago
>x=x+1
I've always heard this explained along the lines of "adds 1 to whatever x is, then puts that value into x, so x is one more than it was before".
- tim333 10y agoI first came across that as a school kid (in BASIC) and didn't find it confusing at all. I still find functional computing confusing - I mean to do something for the numbers 1 to 100 instead of for x = 1 to 100 you have to do some weird tail call recursion which if you are lucky the compiler then converts back to for x = 1 to 100 because that's how processors work efficiently.
- willtim 10y agoI learnt BBC Basic before my high-school algebra and was certainly confused by the different meanings. Don't concern yourself with tail recursion if you are still learning FP, it's just an optimisation, nothing to do with semantics. Python doesn't have it and few people care. What do you want to do with the numbers 1..100? A for loop doesn't give me any hints, which is part of its problem.
- lmm 10y agoDon't bother thinking about what the processor is doing. Just trust it to figure it out. Tell it what to do (which shouldn't involve "weird tail recursion" - rather you probably want to use "map" or similar), and let the runtime/processor do it for you. If and when it turns out to actually be too slowly, and you profile it and can't immediately see why, then you're allowed to worry about that kind of thing. Not before.
- willtim 10y agoThe syntax is trying to look friendly and familiar, but ultimately it's an abuse of a standard mathematical notation that has meant something else for hundreds of years. The original meaning, an equality relation, is still being taught to high-school children today, typically before python is forced upon them.
- hota_mazi 10y agoYou're over dramatizing. The human brain is very good at interpreting things in context and it's really trivial for even middle school kids to understand that `=` in math is different from `=` in programming. Do you want an example of something that beginner programmers struggle with? Pointers.
- augustk 10y agoBut you still need a symbol for the equality operator, so not choosing "=" for that seems rather absurd. It's comparable to making the choice to use + for string concatenation and ++ for (numeric) addition.
- zephyrfalcon 10y agoGood god. If anything is "forced" upon high-school kids, it's algebra. (Maybe ask the average high schooler and see what they have to say about it.) I haven't heard of any schools that make Python mandatory though; where are these located?