A Newborn Baby as a Finite State Machine, Part 2

In the previous post I introduced why modeling software as a Finite State Machine can be useful and used a newborn baby as an example. This post will fill in the transitions for the baby.

I realize I missed two key triggers, hopefully this does not reflect on my real-life parenting ability. Feeding the baby and changing the diaper should have an impact on the state of a newborn, so let’s include those. That gives us the following grid of states and triggers:

Quiet Alert Active Alert Crying Drowsiness Quiet Sleep Active Sleep
Hunger
Dirty Diaper
Lack of comfort
30 min interval
Sudden light/noise
Physical Touch
Feed
Change Diaper

Let’s fill in more of the obvious transitions:

Quiet Alert Active Alert Crying Drowsiness Quiet Sleep Active Sleep
Hunger Crying Crying Crying Crying Crying Crying
Dirty Diaper Crying Crying Crying Crying Crying Crying
Lack of comfort Crying Crying Crying Crying Crying Crying
Time passes Active Alert Drowsiness Drowsiness if was asleep, Quiet Sleep; else Active Alert Drowsiness Quiet Sleep
Sudden light/noise
Physical Touch
Feed
Change Diaper

For simplicity’s sake let’s assume that a baby will always immediately cry when an unhappy event occurs. This is a human being and we cannot expect a program to fully represent the nuances of even a newborn, so this is good enough for now. It is common to need to simplify things for the sake of understanding the program, in any case. It is valuable to simplify the unimportant details for the sake of the important ones.

Next let’s look at what happens as time passes:

Quiet Alert Active Alert Crying Drowsiness Quiet Sleep Active Sleep
Hunger Crying Crying Crying Crying Crying Crying
Dirty Diaper Crying Crying Crying Crying Crying Crying
Lack of comfort Crying Crying Crying Crying Crying Crying
Time passes Active Alert Drowsiness Drowsiness if was asleep, Quiet Alert
else Quiet Sleep
Active Sleep Quiet Sleep
Sudden light/noise
Physical Touch
Feed
Change Diaper

We are saying that a baby will start quiet, become quite active, and then tire herself out into drowsiness until falling asleep, again a simplification. The final simplification we have here is that a baby will get tired if she cries enough without any intervention (not recommended in real life). Note that we put our first conditional transition, when the baby is Drowsy. The baby can be drowsy waking up or falling asleep so we need to know in which “direction” the baby is going to make a decision. Too many conditional transitions can indicate that we need to refactor our States to be clearer. In this case we are fine for now.

Next, let’s cover what I would categorize as the “crying solving” triggers. Most parents are familiar with this checklist of things to check when a baby is crying:

Quiet Alert Active Alert Crying Drowsiness Quiet Sleep Active Sleep
Hunger Crying Crying Crying Crying Crying Crying
Dirty Diaper Crying Crying Crying Crying Crying Crying
Lack of comfort Crying Crying Crying Crying Crying Crying
Time passes Active Alert Drowsiness Drowsiness if was asleep, Quiet Alert
else Quiet Sleep
Active Sleep Quiet Sleep
Sudden light/noise
Physical Touch Quiet Alert Active Alert if discomfort, Quiet Alert
else Crying
Drowsiness Quiet Sleep Active Sleep
Feed Quiet Alert Active Alert if hungry, Quiet Alert
else Crying
Drowsiness Drowsiness Drowsiness
Change Diaper Quiet Alert Active Alert if dirty diaper, Quiet Alert
else Crying
Drowsiness Drowsiness Drowsiness

We added more conditional transitions as the baby could be crying for different reasons. Note that physical touch does not normally wake the baby, but feeding and changing does. We may not have known this when we first took her home, but after being around her we now know how she will respond. This goes back to ensuring you gain the domain knowledge to answer these questions. If you don’t know up front, that is fine. The willingness and ability to find answers or to make assumptions and move on is one thing that separates efficiencers from average software developers.

Finally let’s fill in that last trigger:

Quiet Alert Active Alert Crying Drowsiness Quiet Sleep Active Sleep
Hunger Crying Crying Crying Crying Crying Crying
Dirty Diaper Crying Crying Crying Crying Crying Crying
Lack of comfort Crying Crying Crying Crying Crying Crying
Time passes Active Alert Drowsiness Drowsiness if was asleep, Quiet Alert
else Quiet Sleep
Active Sleep Quiet Sleep
Sudden light/noise Active Alert Active Alert Crying Active Alert Drowsiness Drowsiness
Physical Touch Quiet Alert Active Alert if discomfort, Quiet Alert
else Crying
Drowsiness Quiet Sleep Active Sleep
Feed Quiet Alert Active Alert if hungry, Quiet Alert
else Crying
Drowsiness Drowsiness Drowsiness
Change Diaper Quiet Alert Active Alert if dirty diaper, Quiet Alert
else Crying
Drowsiness Drowsiness Drowsiness

We can see from observing the baby for a while that any sudden noise or light will “jump start” the baby into an active alert state in most cases, unless she is crying or asleep.

This is a great format to transcribe to a computer, such as your automated test suite. However, it is not easy for humans to reason about or to onboard someone how a newborn baby works. In the next post we will see the resulting diagram that we can use to help us and our coworkers reason about newborns.

Social Media Auto Publish Powered By : XYZScripts.com