State

State is a crucial component to how software works. The concept of state in software is much like state in any other context. If you were to ask me what state I am in, I might answer with the JSON in Listing 2.4.

Listing 2.4 My Current State in JSON Form

{ "isSitting": true, "consciousness": "drowsy", "mood": "restless", "heartRate": 73}

After reviewing my state, you might decide that I should take a walk. Similarly, software can use state to determine how it should behave. For example, Gmail has a set of keyboard shortcuts to help users manage their emails more efficiently. One of the most commonly used shortcuts (for me, at least) is typing g and then i to go to the inbox. If I am in the middle of typing an email and I type “give me ...

Get Learning to Program now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.