Comment by donatj

Comment by donatj 4 hours ago

15 replies

> X equals X plus one? That’s not math. That’s a lie.

That's really interesting... My wife, who has no real mathematical background had the EXACT same reaction when I was trying to teach her some simple programming. I tried to explain that equals in that context was more of a storage operator than a statement that said line is true. She found it very frustrating and we gave up on the endeavor shortly thereafter.

I've personally always had a soft spot for languages like TI-BASIC that use a storage operator rather than overloading = so for example:

X + 1 -> X

I wonder if I should try a functional language with her.

brabel 21 minutes ago

Mutation should be an advanced topic in programming teaching. Even in procedural languages. It should be seen as an optimization technique you only use when analysis has shown that to be the only way to solve a difficult bottleneck. Using mutation as a basic tool in programming was a mistake.

tmtvl an hour ago

That's a funny thing to get hung up on, though I can understand it. I suppose that's the downside of some programming languages going with the worst assignment operator. If they didn't they could use = for (numerical) equality tests. If your wife has a strong mathematical background you could also show her some logic programming like Prolog or Mercury.

Also, various ways of assignment:

Pascal style:

  x := x + 1
Scheme:

  (set! x (+ x 1))
Forth:

  x 1 + x !
jasperry 26 minutes ago

Am I wrong to be skeptical that this was a thought author had at 8 years old? I don't doubt that 8-year-olds can learn programming and advanced math, but even the brightest 8-year-old would still be in the "sponge" stage. It's hard to believe they would have a sufficiently fixed idea about algebra to be troubled that X = X + 1 is "wrong".

jacquesm an hour ago

This blocked me from understanding computer programming for 3 years. I thought of 'variables' as immutable and the fact that they were not didn't really click at all. Once I mentally transitioned from 'it's a label attached to a value' to 'it's a named box which holds a value' life got a lot easier. I was 15 when it finally clicked (on a TI programmable calculator...).

  • galangalalgol 32 minutes ago

    I wonder if haskell would have made more sense to you at the time with everything being immutable.

ngriffiths 3 hours ago

I think it makes more sense in languages where you use the "let" keyword. Then it sounds like assignment, though you still have to get comfortable with the X being on the right side too.

SeanDav 4 hours ago

It is not a lie it is just apparently familiar notation that actually has an entirely different meaning. It is not an equation, it is an assignment.

X := X + 1 is perhaps less confusing, even if meaning the same thing.

  • sodapopcan 27 minutes ago

    Although in Erlang it's closer to an equation with assignment being a side effect. `=` is the pattern matching operator.

        Eshell V15.2.6 (press Ctrl+G to abort, type help(). for help)
        1> X = 1.
        1
        2> X = X.
        1
        3> 1 = X.
        1
        4> X = 2.
        ** exception error: no match of right hand side value 2
        5>
  • npteljes 3 hours ago

    That's exactly right. Looking at the Assignment Operator Wiki page, it's also clear where these notations come from.

    I think an easy way to look at it, for someone coming from a math background, is to think of programming lines as instructions, instead of statements. x=x+1 can be then read as "let x be x+1", and that's it.

    https://en.wikipedia.org/wiki/Assignment_(computer_science)

macintux 2 hours ago

I've shared it here once recently, so might as well again.

I gave a talk at Midwest.io (sigh, such a great conference, shame it faltered) building Erlang from the ground up, starting with the = sign and the implications (side effects?) of it being a runtime assertion of truth in addition to a binding.

https://youtu.be/E18shi1qIHU

npteljes 3 hours ago

Pascal also had := for assignment, if I remember correctly. I disliked it, to be honest, = is pretty much universally accepted in the IT world to mean "assign to".

I don't think this is something that keeps someone from programming. If it does, then the other 100000 hoops won't be better, every trade has its "why the fuck is this the way it is" moments.

If you'd still try programming with her, I think you could start with a visual programming thing. Maze from Blockly Games is a simple online logic game that can be overcome with visual programming. No need to register or anything. The levels get progressively harder, as it teaches to apply programming concepts, and makes the player combine them. As a programmer, I found the game really fun, and I think it's suitable for beginners as well, seeing how for example LEGO used a very similar system for its programmable sets.

https://blockly.games/maze?lang=en

  • jacquesm an hour ago

    > I don't think this is something that keeps someone from programming.

    Not everybody is wired the same way. That exact thing happened to me, it was some kind of mental block. And when that fell away I found the rest of programming to be fairly easy.

    • npteljes 9 minutes ago

      Thanks for sharing your experience. I guess in a case like this, even trying another language can work.

marcosdumay 2 hours ago

Yes, people with mathematical background tends to fare better with declarative languages.