DEV Community

loading...

What is State in programming?

danpgomez profile image Daniel P-G Originally published at danpgomez.com ・1 min read

I often hear the term "state" being used when describing objects in a program, or even programs entirely, and decided to do a bit of research to get some clarity. I found a few helpful articles and videos (see bottom of post) which brought me to the following conclusion: The concept of State in programming refers to the value of all variables that determine the status or condition of the program or object in question. With this in mind I came up with the following analogy of a coffee maker (somehow most things in my life revolve around coffee ☕️). So in the image below, the coffee maker's state is "power = on" and "status = brewing". Also important to note that state can change based on both internal or external events, such as the user turning off the coffee maker, or it finishing the brewing process.

A coffee maker’s state can be described as “brewing” and/or “on”

Discussion (2)

Collapse
lifelongthinker profile image
Sebastian

Nice analogy. I'd like to add one important thing: State makes programming so difficult because it introduces time, and with time comes change.

In short, space without time or change is just constant and wouldn't have state. State is everything that is not constant.

Collapse
danpgomez profile image
Daniel P-G Author

Oh! I like that! Thank you!

Forem Open with the Forem app