Yeah, this is kind of chaotic but it's actually, in a way, very "natural" and "easy to understand". Not easy to solve, but very natural to see that it's difficult to solve. Basically I think that mutating global variables are actually the most natural way for a human to understand procedures, and supposedly "clearer" methods like FP are only popular among people with very strong mathematical ability, who have also already internalized powerful abstraction abilities that they no longer realize are unnatural, and have also already experienced the difficulty of trying to understand parallelism with only their brains. These people welcome the unnatural constraints of FP with open arms. People coming to programming from the real world, do not (in my experience) welcome the constraints of FP at all. It's very interesting to me that Dynamicland appears (from afar, I've never been there), in it's pursuit of a more natural and "humane" programming, to have basically gone completely the opposite direction to FP. As far as I can tell the entire room/operating system operates on a single massive global database.
programmer 1: Ok... if x is less than 5, set y to 3 programmer 2: Ok... set y to -5, then if... programmer 1: Hey what are you doing? I want y to be 3 programmer 2: No I just set it -5 ...
Why is shared mutable state considered bad? Isn't it an accurate reflection of the universe we live in?No, it is not an accurate reflection. SMS leads to spooky action at a distance. With SMS, I can nail together two pieces of wood in Toronto, and unexpectedly, a house collapses in Los Angeles. SMS enables unpredictable non-local effects. I can't rely on local reasoning to understand what a program is doing.
I think it is unnatural for the value of
>>> a=[1,2,3] >>> b=a >>> a=17 >>> b [17, 2, 3]
to change when I modify
. I've seen lots of evidence on the internet that this is a source of confusion for novice programmers who are encountering Python for the first time.