Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I was reading the \"C++ Coding Standards\" and this line was there: Variables in

ID: 653098 • Letter: I

Question

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?

Explanation / Answer

Doesn't any mutable thing really manipulate state?

Yes.

And what does the "you should have to deal with little state" mean?

It means that less state is better than more state. More state tends to introduce more complexity.

In an impure language like C++, isn't state management really what you are doing?

Yes.

What are other ways to "deal with little state" other than limiting variable lifetime?

Minimize the number of variables. Isolate code that manipulates some state into a self-contained unit so that other code sections can ignore it.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote