A while back I was developing a workflow scheduler. However the run duration kept coming back negative. The runs kept finishing like 15 seconds before they started. Eventually I figured out why; the company had configured a policy to use their custom NTP server, but it was 16.7 seconds off. So my Windows laptop’s time was in the future, but the WSL VM (which ran the program) used another NTP server and was correct. In the end I just added a bodge that made the program request the time from an external server on startup to calculate an offset.

  • expletivedeleted@lemmy.zip
    link
    fedilink
    arrow-up
    23
    ·
    1 day ago

    I was hired to work on a CMS designed for schools. I was tasked with debugging.

    I started off with the newest issues and worked my way back.

    Well, there was a bug where teachers would upload a video but it wouldn’t play on the page. It was plaguing a team of 8 for YEARS.

    It was mentioned in our morning standup, and I decided to fast track it.

    The dude who wrote the code was shrinking the display size in half: well how do you think that would work when a dimension of the video isn’t divisible by 2?

    So, remember, I am the new guy, quickly fixed it using an if/then and the % modulus operator, and lo and behold, the next morning standup I had to explain the fix in front of the project manager, his boss, and the entire team…

    fucking awkward. “You see, there’s this thing in division called a remainder.” This was the first thing in the morning.

    But because the bug had been so ever present, that’s why the boss’s boss attended the standup. God, I just wanted to die.

    • Buddahriffic@lemmy.world
      link
      fedilink
      arrow-up
      2
      ·
      2 hours ago

      Ok, I understand the issue but I don’t understand your embarrassment from it. You didn’t write the initial bug.

      Btw, a faster way to check if a value is even is to just do a bitwise AND on bit 0 (if it is an integer, though it needs to be an integer for modulus to work anyways).

      In many languages it looks like:

      if ( val & 1 ) { \ it is odd }

      Division is a multi-cycle operation but bitwise comparisons are simple enough to be done in a single cycle, or could even be thrown on to instructions as a free extra that doesn’t add any extra cycles (eg any instruction with a bit mask, though it depends on the implementation as to whether it’s done for 0 extra cycles or more).

      Doesn’t really matter for a one off operation like halving the value of video display parameters, but if you have a loop that needs to check a lot of them, the bitwise and will pull ahead.

      And if you’re thinking “well we need to divide by 2 anyways and the modulus is available from that operation as long as the compiler sees it should save the result and the modulus”, a bitwise shift right (non-circular) of 1 is also way faster than divide by 2.

      Both of these can also be generalized for any power of 2, if necessary.

    • cristian64@reddthat.com
      link
      fedilink
      arrow-up
      7
      ·
      1 day ago

      I don’t think I understand what the issue was or what the fix was. Was it a language or system that cannot perform the division with truncation?

      • expletivedeleted@lemmy.zip
        link
        fedilink
        arrow-up
        5
        ·
        1 day ago

        Let’s say height and width are 320x214.

        (these numbers are arbitrarily chosen)

        The code was sizing it down by /2, so now it is 160 by 107.

        Because the width being odd, it would display.

        But:

        if ($width%2) { $width = --$width; }

        Hastily written out on the phone, but that was the fix. This was back with php 5.

          • notthebees@reddthat.com
            link
            fedilink
            arrow-up
            3
            ·
            12 hours ago

            You can’t halve a pixel. Truncating would get around the issue but big issue is that you can’t have a float as a video resolution. The browser should just truncate it regardless but the original code is flawed.

            OPs fix essentially does the same thing.

          • bitfucker@programming.dev
            link
            fedilink
            arrow-up
            7
            ·
            19 hours ago

            For a strong typed language, an integer division should not cast to any other data type. Even assigning a float to an integer should not be allowed (that’s why C is not really strongly typed). I think from the syntax it was PHP. If any of the dimensions were not divisible by 2, then the number changed from integer to float and it could cause an issue somewhere downstream the video processing pipeline.

            • notthebees@reddthat.com
              link
              fedilink
              arrow-up
              1
              ·
              12 hours ago

              I don’t think it’s reexporting a video or something, I think it’s the embed bc it is a CMS. PHP 5 isn’t that old so video in webpages isn’t a novel idea.

              But you’re right. Can’t halve a pixel.

              • bitfucker@programming.dev
                link
                fedilink
                arrow-up
                1
                ·
                11 hours ago

                Do note that PHP5 is old, predating HTML5. Browsers probably still struggle with malformed HTML and in the absence of any sane value, just crash. Also, who knows if it was even HTML. For all I know it could be a flash.

                • notthebees@reddthat.com
                  link
                  fedilink
                  arrow-up
                  1
                  ·
                  9 hours ago

                  Fuck, I forgot about Flash. I didn’t think it was that old. Odds are it’s just some other internal video player tbh.

            • cristian64@reddthat.com
              link
              fedilink
              arrow-up
              1
              ·
              18 hours ago

              OP didn’t say that the problem was with the change in type. I think the interesting part is the downstream issue: what failed when a float was given while an integer was expected?

          • expletivedeleted@lemmy.zip
            link
            fedilink
            arrow-up
            3
            ·
            18 hours ago

            Dude, this reminds me of my coworker who was setting up a network and was trying to figure out a subnet mask, and he said, “I am trying to find a subnet mask between /22 and /23.”

            He spent the entire day on it. I finally had to ask, and once he told me his goal, I of course asked, “how the fuck do you get half of a bit?”

            Oh, the blood drained from his face. “Yeah, bro, that’s CIDR.”

            How does this not make sense? I am spoon feeding this shit. Are you just vibe coding?

      • bss03@infosec.pub
        link
        fedilink
        English
        arrow-up
        3
        ·
        1 day ago

        I think there are some versions of Python and/or PHP where the normal division operator silently promotes to IEEE floats, and you have to explicitly cast back to truncate/floor the value.