Debug your time in range
The 6-week course for diabetic developers to increase TIR by 10%
This is also available as a six-week email course.
How did you feel the last time you were out of range?
It sucked, huh?!
I’ve been a Type 1 for 25 years and I feel you: every injection, test, activity is yet another opportunity to screw it up.
Remember the last time you rage bolussed a high and got low as a result? What about the time you ate the entire kitchen to correct a low and skyrocketed—and then rage bolussed?
You tried so many times to reverse-engineer what the hell is going on. Even the exact same things that worked yesterday don’t work today.
They told you that training is good for your diabetes, but forgot to say exercise makes it harder to control blood sugars.
Let’s not mention weekends and days off are even worse than your week days.
No shit, you are exhausted!
Ciao, this is Riccardo. I’ve been a type 1 for 25 years and a web developer for more than 10 years.
I’m here to help you Increase your Time In Range by 10% in six weekly iterations.
As a sofware developer, I like to keep it simple—boring if you will—and diabetes is no exception.
Table of content
- The first step to 10% more Time In Range
- Tip #1: 100% basal insulin coverage
- Tip #2: TDD your blood sugars
- Tip #3: Remove
ifs from your diabetes management
- Tip #4: Bolusing is an impure function of timing and amount
- Tip #5: The KISS way to highs and lows
- Tip #6: This is how I do it
The first step to 10% more Time In Range
As somebody who's been dealing with T1D for almost 25 years, I'm inspired that you decided to take action. You rock!
Please duplicate the spreadsheet you will use to track your 10% time in range increase in six weeks.
Here's what you need to know about it:
I'll send you the first pro tip soon. In the meanwhile, please setup a reminder and track your blood sugars in the spreadsheet daily.
Tip #1: 100% basal insulin coverage
Have you ever worked in a codebase with a bad test coverage?
You know, those projects with flaky tests failing randomly. Or a green suite that didn't catch a bug that later exploded on production. Or even complete lack of coverage in the area you are supposed to work on.
Not only that gives you zero confidence, but it also destroys your motivation.
Basal insulin is the same thing: with bad basal coverage you chase inexplicables lows and highs all day, with good basal coverage you have a stable flatline you can build upon.
In other words, there's no way you can control your blood sugars if your basal insulin is not tuned in. Absolutely no way.
But how the hell do I fine tune my basal with all the variables that affect my blood sugars? You test drive it—think unit testing where the unit under test is your basal insulin.
Take an average day, be in a fasting state, drink only water, and measure your blood sugars every hour. You want your basal to keep your blood sugars in a flatline plus or minus a small variation (20-30 mg/dl). Here's a more in depth explanation.
Mark a day—or part of a day (e.g., night)—on the calandar and give basal testing a try.
Tip #2: TDD your blood sugars
Would you rather fix a bug in a feature you deployed a few hours ago or a few days ago?
You bet today's bug is the better pick! With the context fresh on your mind, you don't even need to look at the code to know what's wrong.
With blood sugars, it's the same story: you want to debug them the same day and setup your tests for tomorrow—short feedback loops FTW!
At the end of your day, jump into the Today sheet, fill in your readings, and focus on one or two surprising blood sugars: what can you do tomorrow to improve them?
In most cases, there are multiple explanations for a strange number. For example, waking up high could be a consequence of the dawn phenomenon, delayed dinner digestion, or not enough basal. Just pick the theory that sounds the most reasonable.
Here's how I do it:
Remember, numbers are just numbers: they can be surprising but never good or bad. As with a broken CI or an issue on production, we fix it and try to do better next time. As difficult to believe as it sounds, we are not our numbers nor our bugs.
Tip #3: Remove
ifs from your diabetes management
Conditionals are the worst, aren't they?
You add one innocent
if and the code becomes twice as complex. Not to count, you have to double up the tests to cover all the paths.
When calculating insulin, you run a ton of
ifs in your head. And I can guarantee one thing: you'll either make a mistake on the dose or on the timing—most likely, you'll be wrong on both. It's impossible to be as good as a pancreas, but here's the good news: you shouldn't even try.
Don't strive for perfection: if you get to 85 mg/dl while shooting for 100 mg/dl you are golden. But how to reduce the outcome of the inevitable mistakes? You manage the variables.
There are three types of variables that affect your blood sugars: the inevitables, the removables, and the ignorables.
The ignorable variables are the ones you shouldn't even calculate. Fun fact, olives don't really raise my blood sugars, but YDMV (your diabetes may vary).
The removable variables are the things you could avoid. For instance, I always had problems with training early in the morning. I prolly could have made it work, but working out later in the day fixed it.
The inevitable variables are the ones that well.. you cannot avoid, but you can get to know them and limit their impact. For example, I tend to go low when I lie down during the day, so when I do that I eat a sugar cube.
This week, take a look at your variables, analyze them, and develop a model on how to manage them. The best way to study a variable is the one you used for the basal test: remove all the others and focus on the one under test.
PS: You won't like what comes next, but I'd be dishonest if I didn't mention it: the biggest variable when it comes to diabetes is sugars and carbs. The less you consume, the easier is to manage your blood sugars.
Tip #4: Bolusing is an impure function of timing and amount
Wouldn't it be awesome if bolusing could be modeled with a pure function that takes a couple of arguments as an input and returns a unit amount as an output? You bet it would.
Unfortunately, bolusing comes with global state and side effects: hormones, physical activity, food volume, stressors, insulin site, digestion, and Lunar phases are just a few of the variables we deal with.
On top of that, your diet and eating habits are unique to you: I cannot share tactics, but I can suggest a strategy.
1. Make sure your basal insulin is on spot
If you want to achieve good control, don't bother with fine tuning your bolus until you are stable in a fasting state. Basal testing will get you there!
2. Get the timing and amount of your bolus right
With the basal in check, you are halfway there—now you need to cover the short-term bumps. Imagine insulin as a curve that lowers your blood sugars, and food as a curve that raises them. You want those two curves to match as much as possible in amplitude and shape to nil each other.
2.A. Carbs are not all made equal
You could know the precise amount of carbs in a meal and your insulin to carb ratio, still it wouldn't be enough for optimal control—even if you magically removed all the other variables. Carbs are like temperature, you are interested in perceived degrees not absolute ones. And they don't impact all the same.
In general, carbs act fast—some even faster. So you may want to pre-bolus and start eating as soon as insulin starts lowering your blood sugars to make the curves cancel out.
2.B. Proteins and fats count
Proteins and fats raise your blood sugars too. I'm sure you witnessed it: you think you nailed the bolus but a second wave raises your blood sugars. Pizza anyone?
Proteins and fats are converted to glucose but at a lower speed than carbs. Also, the less carbs you eat, the more you convert. Additionally, fats make you insulin resistant and slow down your digestion.
You can use the Warsaw approach as a starting point. But, as a general rule, you cover proteins and fats with an extended bolus.
3. Be like water
Bruce Lee would have killed it as a diabetic:
Global state is like hidden input to a function. If your basal insulin is fine tuned (tip #1), you create a good model to take care of your biggest variables (tip #3), and you develop the habit of daily retrospectives (tip #2), you expose global state and can manage it.
Tip #5: The KISS way to highs and lows
How does it feel to ship a bug to production? Bad, huh?!
Well, actually it feels the same way as deploying correct code; it's only when you realize you shipped a bug that it stings.
Now, let me ask you: how does it feel to inject the wrong dose of insulin?
This is why we cannot focus only on the happy path: you and I know that some bugs will slip through together with some out-of-range blood sugars. Luckily, the goal is not perfection but a 10% time-in-range increase.
And if you can manage 10, you can do even more.
Before we get into highs and lows, there's one important thing: you need to be comfortable with your range. A number mid-range is as good as a number closer to the boundaries. Also, some fluctuations are expected—it's impossible to flatline.
The best way to handle a number out-of-range is not to get there in the first place. And to do that you need one thing: flatten the curves.
Imagine for a second trying to bolus a meal that raises you by 1000 mg/dl (56 mmol/l) almost instantly. You simply cannot do that while staying in range: insulin follows a parabolic curve of action, while the meal in case is a sudden spike. So you would need to choose between going (dangerously) low or going high. Also, making insulin work faster wouldn't help either, it would actually make things riskier.
Now consider a meal that raises you by 250 mg/dl (14 mmol/l) over the course of four hours. Matching the raise with insulin is not easy (what is with diabetes?) but it's tractable. Most importantly, this situation is forgiving: even if the curves don't perfectly match—and they never will—you have all the time to correct and stay in range.
I'm not suggesting you to eat super–low-carb, or skip meaningful experiences that result in spikey curves—it's your choice. But some stuff will make your blood sugars more difficult to manage and you need to be mindful about it.
Smaller input, smaller output. Some would say KISS.
The second best way to handle a number out-of-range is to bring it in as fast as possible. If it's a low, you want to consume fast acting glucose that you can properly dose. If it's a high, you can make insulin work faster by injecting it intramuscularly, taking a warm bath, or going for a brisk walk.
Do everything in your power to not over correct. It boils down to two choices: you can either stop the rollercoaster or perpetuate it. And we both know that a number out-of-range is frustrating, but a number-out-range after an over-correction feels like shit.
Also, lows are not an excuse to eat something delicious. Focus first on regaining stability with a precise tool like sugar or dextrose before adding more curves. KISS, right?
Finally, make sure you have glucagon and a trusted person within reach. Nobody likes to rollback a deploy, but you will be glad you prepared a plan b if the unexpected happens.
Tip #6: This is how I do it
This week, I turn the spotlight on myself and share with you how I do it—including controversial takes, strange tricks, and Italian hand gestures.
I hope you can take some inspiration, but I encourage you to find your way. There are many people out there with better results than mine making different compromises and following a different strategy. With some hard work, I'm sure you can tailor a lifestyle around your values, needs, and wishes.
I (Riccardo Odone) am not a doctor. I share the perspective of somebody who has been dealing with type 1 diabetes 24/7 for 25 years. Nothing that I say constitutes medical advice. Always consult with a real doctor before making any changes.
Be a skeptic. I mean it.