Meme transcription:

Panel 1: Bilbo Baggins ponders, “After all… why should I care about the difference between int and String?

Panel 2: Bilbo Baggins is revealed to be an API developer. He continues, “JSON is always String, anyways…”

    • flamingo_pinyata@sopuli.xyz
      link
      fedilink
      arrow-up
      27
      ·
      edit-2
      6 months ago

      Just reminded me of an argument trying to explain that arithmetic with floating point numbers is not always correct to a coworker who was a mathematician just starting in software dev.

      In a mathematicians mind the fact that an arithmetic operation can produce inaccurate result is just incomprehensible

      • Scrubbles@poptalk.scrubbles.tech
        link
        fedilink
        English
        arrow-up
        16
        ·
        6 months ago

        The fun differences between the perfect world of theoretical and the realistic. Everyone thinks of computers as perfect - but it’s not until you’re asked to solve “How do you store decimals using only 0s and 1s?” does it start to click. Not as easy. It’s why I’m hesitant to hire bootcampers into my roles. Bootcamps are great, and they get more people coding, but you don’t learn that theory behind the scenes - you don’t really know what the computer and operating systems are doing. For 90% of the time it doesn’t matter, it’s abstracted away - but that last 10% man, that can really fuck up an entire system.

    • andyburke@fedia.io
      link
      fedilink
      arrow-up
      11
      ·
      edit-2
      6 months ago

      You are a fintech dev using floating point? And your advice is to encode things as strings?

      This is why I got out of fintech.

      (I am sorry, I know there are horrors and I am sure I am not familiar with your exact scenario.)

      Edit: just for anyone who passes by: try to stick with integers in a currency’s smallest unit of division. (This is only one small bit of this problem, but the number of times I have seen currency values in floating point makea me psychotic.)

      • Scrubbles@poptalk.scrubbles.tech
        link
        fedilink
        English
        arrow-up
        7
        ·
        6 months ago

        Until you get to multi currency, which is why I don’t support using ints or longs, and strings are still the only way. There are currencies that have no precision, and others that have 3 or more digits of precision - and then you’re looking at doing calculations each time. Strings are the safest way to make sure you’re representing exactly what you want to when sending data over the wire or persisting

      • bleistift2@sopuli.xyzOP
        link
        fedilink
        English
        arrow-up
        2
        ·
        6 months ago

        try to stick with integers in a currency’s smallest unit of division

        And then the marketing department comes up with products that cost 1.5ct apiece.

    • frezik@midwest.social
      link
      fedilink
      arrow-up
      2
      ·
      6 months ago

      JSON numeric encoding is perfectly capable of precise encoding to arbitrary decimal precision. Strings are easier if you don’t want to fuck around with the parser, though.

      • Scrubbles@poptalk.scrubbles.tech
        link
        fedilink
        English
        arrow-up
        5
        ·
        6 months ago

        Correct, JSON can handle any precision, because it’s just dumped as a string anyway, just not enclosed in the "". However, as you mentioned, as soon as it comes through the parser it’ll put it into an underlying float value. In C# I create a save high precision attribute that will take the value and put it directly into a decimal. In JS I’m sure there’s some way to do that, but that parser is way less extensible compared to C#. However, this also all assumes you know the client will parse it correctly, overriding the default behavior. Safest is to just send it as a string, and then create your parsers to automatically send to and from strings