• bioemerl@kbin.social
    link
    fedilink
    arrow-up
    7
    arrow-down
    5
    ·
    1 year ago

    Yep, I always default to the largest possible type because compute is less valuable than my time on the weekend and the potential for any sort of overflow.

    Long

    Double

    Big int

    Etc.

    • Anomandaris@kbin.social
      link
      fedilink
      arrow-up
      11
      ·
      edit-2
      1 year ago

      I don’t know if I’d go that far. If you’re talking about a quick script then sure, whatever gets the job done. But for any actual project the use of good, consistent typing does a lot for readability and future-proofing. And in strongly-typed languages it can have a notable affect on the overall functionality too.

      If you can’t tell from context whether something is a float or if it’ll overflow the int max then you probably need to re-think the entire method.

      • bioemerl@kbin.social
        link
        fedilink
        arrow-up
        1
        ·
        1 year ago

        The compiler doesn’t know what numbers are going to go into a variable, that’s a runtime thing. They might prevent a crash that way, but a crash or not doesn’t matter when people need the number in the database and the database doesn’t let you put the number in the database.

        • darcy@sh.itjust.works
          link
          fedilink
          arrow-up
          1
          ·
          edit-2
          1 year ago

          i mean, at least with rust, running in debug mode (or release with flags) will hard panic if an overflow occurs, bc it checks everytime a number is changed. it is obviously less performant to do this, so it does not check when running in release/production mode. the problem is if you need to have no overflows occur, it is better to throw an error and exit the program, than cause unexpected behaviour, eg. as an incorrect, but existing array item. this could be hard to find the cause of the bug if it doesnt throw

          • bioemerl@kbin.social
            link
            fedilink
            arrow-up
            2
            ·
            1 year ago

            I’m a C# dev so I forget that anything that’s not this case even exists. Agreed 100 percent.