• xav@programming.dev
    link
    fedilink
    arrow-up
    4
    ·
    3 days ago

    C++ has proven (at great expense) that documenting footguns is not sufficient. At all. You have to make them impossible.

    • sugar_in_your_tea@sh.itjust.works
      link
      fedilink
      arrow-up
      3
      ·
      3 days ago

      Then make it explicit, e.g. Duration::from_days_monotonic(...) . I’m also fine with just having constants, but those are nightly only. I want a way to clearly express durations in terms of days, and constants and functions are clearer than comments.

      • SorteKanin@feddit.dk
        link
        fedilink
        arrow-up
        1
        ·
        3 days ago

        I want a way to clearly express durations in terms of days

        The argument here is that expressing durations in terms of days is a bad idea because “day” does not really convey a very precise duration, as it is not always 24 hours.

        Maybe you won’t be confused by Duration::from_days right now, but maybe a junior dev before they get their coffee, or even the senior dev on code review might miss stuff like that.

        • sugar_in_your_tea@sh.itjust.works
          link
          fedilink
          arrow-up
          3
          ·
          3 days ago

          But a day does have exactly 24 hours, at least when using Unix timestamps. Leap seconds aren’t accounted for in a Unix timestamp, and Unix timestamps assume UTC timezone, which doesn’t have daylight savings.

          If you don’t make a “from_days()” or “DAYS” constant, people will make their own and they’ll be wrong in exactly the same way as if that function or constant was defined in the stdlib, but at least in the stdlib, you have the opportunity to centralize the documentation for it and maybe educate that junior dev before they make a mistake.