It is tempting to conclude this discussion by saying that, by introducing assignment and the technique of hiding state in local variables, we are able to structure systems in a more modular fashion than if all state had to be manipulated explicitly, by passing additional parameters.
通过局部状态可以使得我们更加模块化的来构建系统.
引入赋值的代价
那么,代价是什么呢?
替换模型在这里不再适用了
由于引入了赋值,函数的执行顺序变得重要了,我们也失去了函数式编程的一部分优雅
我们不得不接受命令式编程一样的复杂性
programming with assignment forces us to carefully consider the relative orders of the assignments to make sure that each statement is using the correct version of the variables that have been changed.This issue simply does not arise in functional programs
The central issue lurking beneath the complexity of state, sameness, and change is that by introducing assigment we forced to admit time to our computational models.
what makes this complicated is that more than one process may be trying to manipulate the shared state at the same time.
The basic phenomenon here is that synchronizing different processes, establishing shared state, or imposing an order on events requires communication among the process.
We can model the world as a collection of separate, time-bound, interacting objects with state, or we can model the world as a single, timeless, stateless unity.