I was reading the "C++ Coding Standards" and this line was there:
Variables introduce state, and you should have to deal with as little state as possible, with lifetimes as short as possible.
Doesn't anything that mutates eventually manipulate state? What does you should have to deal with as little state as possible mean?
In an impure language such as C++, isn't state management really what you are doing? And what are other ways to deal with as little state as possible other than limiting variable lifetime?
Best Answer
Yes.
It means that less state is better than more state. More state tends to introduce more complexity.
Yes.
Minimize the number of variables. Isolate code that manipulates some state into a self-contained unit so that other code sections can ignore it.