DEV Community

Daniel P-G
Daniel P-G

Posted on • Originally published at danpgomez.com

What is State in programming?

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”

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Top comments (1)

Collapse
 
danpgomez profile image
Daniel P-G

Oh! I like that! Thank you!

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay