• EnderMB@lemmy.worlddeleted by creator
    link
    fedilink
    arrow-up
    157
    ·
    2 years ago

    I’ve honestly never understood why someone at Google or Mozilla hasn’t decided to write a JavaScript Standard Library.

    I’m not opposed to NPM, because dumb shit like this happens everywhere. If such a package is used millions of times a day, perhaps it would make sense to standardise it and have it as part of the fucking browser or node runtime…

    • seatwiggy@lemmy.dbzer0.com
      link
      fedilink
      English
      arrow-up
      24
      ·
      2 years ago

      There’s a js runtime called bun that is 90-something% feature equivalent to node and also has built in alternatives to many packages like express and bcrypt. I haven’t used it myself so I can’t speak to its quality but it’s always nice to see a little competition

      • Dr. Moose@lemmy.world
        link
        fedilink
        English
        arrow-up
        17
        ·
        2 years ago

        So is Deno! You can easily import npm: and node: packages and run typescript without transpiling. With Bun and Deno there’s no reason to use Node tbh.

        • sfxrlz@lemmy.world
          link
          fedilink
          arrow-up
          5
          ·
          2 years ago

          For starting new projects i absolut agree. At work we have a legacy react app that just will not run on bun and for deno we would probably have to rewrite some stuff.

          • Dr. Moose@lemmy.world
            link
            fedilink
            English
            arrow-up
            5
            ·
            2 years ago

            I’ve updated some legacy nodejs to Deno recently and it’s actually not bad! If you’re using serverless Denoflare is super convenient and DTN is a tool for building Deno to NPM (both esm and commonjs) so you can have easy backwards compatibility if needed, it even shims all of the Deno standard lib.

            It’s really impressive what Deno and Bun people have done - for the first time I actually somewhat enjoy server side JS!

            • sfxrlz@lemmy.world
              link
              fedilink
              arrow-up
              3
              ·
              2 years ago

              That sounds neat. For our nodejs server this could be done without too much effort. Will keep that in mind, thanks. But I also have to check for the cra app we’re having a lot of issues with.

      • oortjunk@sh.itjust.works
        link
        fedilink
        arrow-up
        5
        arrow-down
        1
        ·
        2 years ago

        Bun is used by us in production, in dev, everywhere. It’s great. We don’t even use (p)npm to build js packages on our docker images for apps anymore.

    • mindbleach@sh.itjust.works
      link
      fedilink
      arrow-up
      21
      ·
      2 years ago

      That’s basically how Javascript gets extended. I put off learning jQuery for so long that all the features I’d want are now standard.

    • rimjob_rainer@discuss.tchncs.de
      link
      fedilink
      arrow-up
      22
      arrow-down
      6
      ·
      2 years ago

      I wish they would replace JavaScript with something that was made for what it’s used for. JavaScript should have died years ago.

  • TootSweet@lemmy.world
    link
    fedilink
    English
    arrow-up
    159
    arrow-down
    3
    ·
    2 years ago

    I’ve literally told my coworkers “I’m not saying we should never use dependencies. But every time you add a dependency, you should hate yourself a little bit more. Some self flagellation can’t hurt either.”

    • lad@programming.dev
      link
      fedilink
      English
      arrow-up
      13
      arrow-down
      2
      ·
      2 years ago

      So, every time I use a library to recognize patterns on a picture, to interact with Kafka, do some SSL, or do database mapping, I should hate myself, noted

      We did Elastic API integration in Java by creating and maintaining huge half-codegenerated transformer from code to Elasticsearch’s JSONs, it was a pain and it was source of more than one error

      Dependences should be reviewed and audited to make sure they do what you need and they are worth using. Just making everything in-house gets you nowhere most of the time

      • aaro@lemmy.world
        link
        fedilink
        arrow-up
        19
        ·
        2 years ago

        Nobody is arguing that you should never depend on anything and create everything yourself, but adding a dependency for literally a one liner function is awful. Like one of the Go proverbs goes, a little copying is better than a little dependency.

        • lad@programming.dev
          link
          fedilink
          English
          arrow-up
          3
          ·
          2 years ago

          Yeah, there’s mention of doing the opposite in C++ community in a neighbouring thread

      • JackbyDev@programming.dev
        link
        fedilink
        English
        arrow-up
        3
        ·
        2 years ago

        That is what they were getting at by some self flagellation can’t hurt either. That sometimes “hating yourself” (adding dependencies) is worth it.

        • lad@programming.dev
          link
          fedilink
          English
          arrow-up
          1
          arrow-down
          1
          ·
          2 years ago

          I read it as “also throw in some physical pain cause just feeling bad is not quite enough” 🤔

  • floofloof@lemmy.ca
    link
    fedilink
    English
    arrow-up
    85
    ·
    2 years ago

    It looks like “is-number” was never more than a few simple lines of code. It still has 68 million downloads per week.

    https://www.npmjs.com/package/is-number

    I checked one of our main projects at work, and it’s in there as a dependency 6 levels deep via the “sass” package.

    • sus@programming.devOP
      link
      fedilink
      arrow-up
      69
      ·
      2 years ago

      is-number is a one-line function. (though it’s debatable if a function that complex should be compressed to one line)

      You may have heard of a similar if more extreme “microdependency” called is-even. When you use an NPM package, you also need all the dependencies of that package, and the dependencies of those dependencies recursively. Each package has some overhead, eventually leading to this moment in time.

      • sparkle@lemm.ee
        link
        fedilink
        Cymraeg
        arrow-up
        11
        arrow-down
        1
        ·
        2 years ago

        Web bloat in a nutshell and why we need to switch to things like Web Assembly more than ever. It’s not WASM, but I used Laminar which is a Scala.js library, and it’s the absolute pinnacle of (frontend) web development. Scala in general is just really great for idiomatic web code, its flexibility is unbeatable.

        Another amazing alternative would be anything Rust. In fact I’ve used that much more than Scala for web. I’ve mainly used Leptos for full-stack and and Actix for backend, but I’ve seen Dioxus and Axum in good use and they both seem really great too.

        Apparently Lemmy uses Leptos for its UI so… that’s a +1.

    • Gamma@beehaw.org
      link
      fedilink
      English
      arrow-up
      19
      ·
      2 years ago

      It handles a few weird edge cases, mostly. Only 7 meaningful lines of code and almost 70M downloads week!

    • lad@programming.dev
      link
      fedilink
      English
      arrow-up
      4
      ·
      2 years ago

      I’m not sure, this is a valid estimate. If they were to replace is-number with its contents, that would mean that the economy is only in HTTP-related overhead.

      It maybe will make difference because of building phase, lock-files, package-files, but I am not sure that data-traffic difference is that big

  • Randelung@lemmy.world
    link
    fedilink
    arrow-up
    42
    ·
    2 years ago

    Seems to me the only reason for these kind of dependencies to exist in the first place is that people really, really, really, REALLY can’t code.

    • Bourff@lemmy.world
      link
      fedilink
      arrow-up
      22
      arrow-down
      1
      ·
      2 years ago

      Well javascript is the default language of the web, so no surprise it attracts a lot of newbies.

      • Randelung@lemmy.world
        link
        fedilink
        arrow-up
        12
        ·
        2 years ago

        Yeah but if noobs use it as a dependency, who made the package?

        And what projects are noobs working on that trigger 440GB of weekly traffic?

        I fear most noobs remain noobs.

        • Bourff@lemmy.world
          link
          fedilink
          arrow-up
          4
          ·
          2 years ago

          Don’t ask me, all these one-line packages are ridiculous, cause greater issues than whatever they solve, and are (part of) the reason why js and it’s ecosystem are not considered seriously by other developers.

  • 418teapot@lemmy.world
    link
    fedilink
    English
    arrow-up
    27
    arrow-down
    3
    ·
    2 years ago

    It’s kind of insane how bad this whole is-number thing is. It’s designed to tell you if a string is numeric, but I would argue if you’re ever using that you have a fundamental design problem. I hate dynamic typing as much as anyone else, but if forced to use it I would at least try to have some resemblance of sanity by just normalizing it to an actual number first.

    Just fucking do this…

    const toRegexRange = (minStr, maxStr, options) => {
      const min = parseInt(minStr, 10);
      const max = parseInt(maxStr, 10);
      if (isNaN(min) || isNaN(max)) throw Error("bad input or whatever");
      // ...
    

    Because of the insanity of keeping them strings and only attempting to validate them (poorly) up front you open yourself up to a suite of bugs. For example, it took me all of 5 minutes to find this bug:

    toRegexRange('+1', '+2')
    // returns "(?:+1|+2)" which is not valid regexp
    
    • thesmokingman@programming.dev
      link
      fedilink
      arrow-up
      41
      ·
      2 years ago

      The problem is the underlying API. parseInt(“550e8400-e29b-41d4-a716-446655440000”, 10) (this is a UUID) returns 550. If you’re expecting that input to not parse as a number, then JavaScript fails you. To some degree there is a need for things to provide common standards. If your team all understands how parseInt works and agrees that those strings should be numbers and continues to design for that, you’re golden.

      • 418teapot@lemmy.world
        link
        fedilink
        English
        arrow-up
        12
        ·
        2 years ago

        Yeah good point. I suppose the problem is this function that operates on numbers allows numeric strings to be passed in in the first place. The only place where I would really expect numeric strings to exist is captured directly from user input which is where the parsing into a numeric data type should happen, not randomly in a library function.

  • KillingTimeItself@lemmy.dbzer0.comBanned
    link
    fedilink
    English
    arrow-up
    16
    arrow-down
    6
    ·
    2 years ago

    i think programmers need a self inflicted rule of it being less than 500 lines of code means you need to write it instead of using a pre written package/library.

    On the other hand, we could make the packages like is-number the worst possible way of checking if something is a number, which would be really fucking funny…

      • KillingTimeItself@lemmy.dbzer0.comBanned
        link
        fedilink
        English
        arrow-up
        5
        arrow-down
        3
        ·
        2 years ago

        well obviously shit like wozmon exists, but there definitely needs to be a rule to prevent handicap shit like “is-number”

        the vast majority of programmers have the problem solving capability of a child who took shit apart constantly due to autism.

    • jonne@infosec.pub
      link
      fedilink
      arrow-up
      6
      ·
      2 years ago

      Eh, I can see why you’d want something like that in a language like JavaScript where pretty much all native ways of validating input have weird edge cases. Sometimes you just want the community to figure it out for you instead of reinventing the wheel and finding out you missed something later on.

      A whole package that handles validation of inputs, or a math package would be better than a package that just has one function tho.

      • KillingTimeItself@lemmy.dbzer0.comBanned
        link
        fedilink
        English
        arrow-up
        5
        ·
        2 years ago

        yeah, generally it seems like you want a more broad package, if for something like validating input, it would be comprehensive across all input for example.

        There’s one package on npm called is-even and i think another called is-odd, which according to the author are “learning experiences” which have, considerable amounts of downloads, even though it’s literally just is-even checking. Shit like that should probably get you banned from using keyboards for the rest of your life lol