Once again rewriting my health program in another programming language, this time in c++23: cvdg/cpp-health.

I wrote a simple routine to loop over all entries in the health table to validate:

  • All dates are present.
  • All values are sensible.
bool Health::is_valid()
{
    bool valid = (sleep_score >= 0) && (sleep_score <= 100);
    valid = valid && (body_battery_max >= 0) && (body_battery_max <= 100);
    valid = valid && (body_battery_min >= 0) && (body_battery_min <= body_battery_max);
    valid = valid && (active_time >= 0) && (active_time <= 1440); // 1440 min = 24 hour = 1 day
    valid = valid && (defecation >= 0) && (defecation <= 5);
    return valid;
}

Validating data from a little over a year, I found:

  • All dates were present.
  • One record had invalid values.

Lessons learned:

  • Always use constraints in the database.
  • There must be a simpler way to loop over a range og dates in c++.