• lib1 [comrade/them]@hexbear.net
        link
        fedilink
        English
        arrow-up
        13
        ·
        edit-2
        1 day ago

        Kevlin Henney did a presentation which included a code review of the left pad package. Several of his unit tests failed.

        The code in question wasn’t particularly well written or anything
        module.exports = leftpad;
        
        function leftpad (str, len, ch) {
            str = String(str);
        
            var i = -1;
        
            ch || (ch = ' ');
            len = len - str.length;
        
        
            while (++i < len) {
                str = ch + str;
            }
        
            return str;
        }
        
        And this is the package that it was replaced with. It also failed several tests
        'use strict';
        module.exports = leftPad;
        
        var cache = [
          '',
          ' ',
          '  ',
          '   ',
          '    ',
          '     ',
          '      ',
          '       ',
          '        ',
          '         '
        ];
        
        function leftPad (str, len, ch) {
          // convert `str` to a `string`
          str = str + '';
          // `len` is the `pad`'s length now
          len = len - str.length;
          // doesn't need to pad
          if (len <= 0) return str;
          // `ch` defaults to `' '`
          if (!ch && ch !== 0) ch = ' ';
          // convert `ch` to a `string` cuz it could be a number
          ch = ch + '';
          // cache common use cases
          if (ch === ' ' && len < 10) return cache[len] + str;
          // `pad` starts with an empty string
          var pad = '';
          // loop
          while (true) {
            // add `ch` to `pad` if `len` is odd
            if (len & 1) pad += ch;
            // divide `len` by 2, ditch the remainder
            len >>= 1;
            // "double" the `ch` so this operation count grows logarithmically on `len`
            // each time `ch` is "doubled", the `len` would need to be "doubled" too
            // similar to finding a value in binary search tree, hence O(log(n))
            if (len) ch += ch;
            // `len` is 0, exit the loop
            else break;
          }
          // pad `str`!
          return pad + str;
        }
        
        • chgxvjh [he/him, comrade/them]@hexbear.net
          link
          fedilink
          English
          arrow-up
          18
          ·
          1 day ago

          Not really caring about things working correctly didn’t start with LLM coding assistants/agents. Outside of a few industries programming never was a serious engineering discipline and people mostly rejected the idea that it should be one.

          • SwitchyandWitchy [she/her]@hexbear.net
            link
            fedilink
            English
            arrow-up
            12
            ·
            edit-2
            1 day ago

            brogrammers rejected it. Nerds like Margaret Hamilton stood on principle

            This caption is misleading btw. She never worked directly for NASA, she worked at MIT who were contracted by NASA for the software.

            I also know people who have worked in nuclear energy and aviation software and they are really serious about not taking shortcuts. And regularly complain about higher ups saying things and occasionally pressuring them against industry standards in the name of speeding things up.

              • SwitchyandWitchy [she/her]@hexbear.net
                link
                fedilink
                English
                arrow-up
                3
                ·
                22 hours ago

                For some of the really flight critical stuff that I picked their brains on, the on-cpu cache was disabled because using it would make deterministally analyzing the executive time too difficult. There also wasn’t a pre-emptive multitasking scheduler but instead every task would run during a scheduled time slot in a big superloop.

                All of this caution actually made the software a lot more primitive than the software that Margaret Hamilton led the development of for the Apollo program, but these days cpu cycles and memory are a lot cheaper than the engineering time to implement all these things in a safe way, or so they said.

          • SoyViking [he/him]@hexbear.net
            link
            fedilink
            English
            arrow-up
            9
            ·
            1 day ago

            Clients want new shiny features and they want them fast and they want them cheap and they want to change their scope 20 things during the project. They do not want to pay for boring unit tests that confirms that the system works.