And it's almost tragicomic to see how imperative programmers struggle to even see the actual real issue presented in this snippet.
And it's almost tragicomic to see how imperative programmers struggle to even see the actual real issue presented in this snippet.
It does seem you were complaining about the syntax of assignment.
In the other comments it was clearer that your main complaint is that it's hard to compose mutations to reach a desired state. I agree! You should've led with that!
The syntax is of course also confusing. If you show the above line to a 6. grade child they will tell you that that line makes no sense, obviously.
That's why this example is so good! For someone without exposition to (imperative) programming it's completely nuts. But after some "brainwashing" people don't even recognize how weird the example is actually. My hope is always this makes people think (at least after explanation) a little bit whether they maybe just internalized some actually unintuitive stuff and now think that's the "normal" way to look at things, even it's actually not if you come in just with the knowledge from school.
Not everybody remember that but most people have for example major issues in grasping a loop with a counting variable in the beginning. It's just not so easy to "do the computation" in your head and track the state of your variable. Variables as such are already confusing to most people. Beginners often use them like constants and declare new ones when they actually need to assign a new value. I've see this pattern quite often! If you ask why it was done this way the answer is often "because re-assignment is confusing"…
x <- x + 1;
(BTW be careful about assuming you're the brightest guy in the room, how others "struggle to even see" when you do, and with such clarity)
> OK, how about
> x <- x + 1;
Better.
From such syntax you can at least guess that mutation is happening there.
Still nothing you would show a newcomer in a FP-programming introduction.
(I'm not sure why your comment got down-voted. I can only up-vote it, so I did; to battle stupid down-votes because "feels"…)
Your complaint is that the '=' is used in a different domain than programming with a different use. Rightly or wrongly people will adjust to different notations very easily, homonyms in natural languages rarely cause problems because of the context. Same here, this is C/C++ not formal logic.
Once somebody is told 'this is mutation' and it sinks in, it's not a problem.
You make the bigger claim that FP is easier to understand, and I don't buy it. If you want to put forward that, back it up with some evidence. Personally I believe that it depends on the person. I did a brief introduction to FP to a couple of mathematicians and they got it immediately, but then they were extremely bright and had minds naturally suited to handling abstractions. (edit: which I am not and have not, respectively)
And one of them was not allergic to learning C either, and he got a few lessons in that too.
I worked with one person who simply couldn't understand the concept of passing a function around like any other piece of data.
It frustrates me when people (like you) insist that one programming paradigms is The Truth because, the truth is, you need all of them and you need to apply them at the right time – 00, FP, logic, and yes, procedural. If you can't do that, if you're too hung up on one-way then it speaks of inexperience. As a programmer you're there to deliver a solution, not a technology, and I've been involved in the mess when someone far too inexperienced pushed for the tech rather than the saleable product.
Final note, the inventor of Scala is Martin Odersky and I was watching one of his videos on YouTube where he very much surprised me by saying something about allowing Scala to be imperative for when imperative solutions were the more concise answer. And in the end, all computers are state machines.
So please, loosen up your presumptions; the world is a messy place and you need to allow for that.
Would it not have been simpler to write the new text over the top of the old comment?
(edit: replaced dumb with unhelpful)
> Would it not have been simpler to write the new text over the top of the old comment?
But yeah. It's just dumb I guess.