3 ms·
It's natural to think in terms of "mutating the real world", but I don't think it's natural to introduce artificial mutable state at all. You say "clean all th
by qsort 5y ago
It's natural to think in terms of "mutating the real world", but I don't think it's natural to introduce artificial mutable state at all.
You say "clean all those dishes", not "let x=0, then while x<N, clean the x-th dish from the top, then let x = x+1"
Ask someone without a scientific background to solve (a * b) + (c * d) with a (physical, non-software) calculator. The "correct" answer is to do something like: a * b, M+, c * d +, MR. What they will do is: solve a+b, write down the result, then do the rest. They don't think of a calculator as something stateful.
- mannykannot 5y agoI'm not following here - if it is not a typo, why would you expect someone to solve a+b here? But if we are using calculators, then depending on the make and model, you might do a b * c d * +, Which achieves the goal your second paragraph is aiming for: getting rid of (or at least abstracting away) any explicit use of incidental or intermediate state (which takes the form of memory operations in conventional calculators.) RPN calculators (and programming languages), however, never became popular, and I strongly suspect that is because their expressions are often objectively harder for humans to comprehend, no matter how elegant RPN seems.
- qsort 5y agoIt's a typo, I meant a * b. I agree on RPN, that was the point I was trying to make. RPN is more powerful, but is stateful and uses a rather complicated and unintuitive form of state (a stack). In my experience it's not true that people find it more intuitive to work with arbitrary mutable state of the kind imperative programming languages traditionally have.
- janto 5y agoThe difficulty with using M+/MR is that the value does not remain visible or at hand. It's like the calculator loses its state. So people write the state down instead. This suggests they know it is stateful, they're just not familiar with managing it.
- janto 5y agoI don't think in your dishes example that `x` is introduced complexity. The mutable `x` is used here to reflect the mutable state of the physical world, so it'll come naturally to anyone capable of thinking symbolically and want to describe how to clean. If you did that functionally, the mutability would still need to be reflected somewhere, only now it might be implicitly in the runtime.