• ChaoticNeutralCzech ( ChaoticNeutralCzech@feddit.org ) 
    link
    fedilink
    English
    arrow-up
    76
    ·
    edit-2
    2 years ago

    If you think is-number can be replaced with a one-liner, you don’t have the enterprise code mindset. What if the world gets more inclusive and MMXXIV, ½ and ⠼⠁ become recognized as numbers? 𒐍𓆾 were numbers in the past but what if people start assigning numeric value to other characters? Are 🖐🔟💯🆢🂵🀌🁅 numbers of the future???
    /s

    I’m not even all kidding, Regex implementations are split on whether “٣” matches \d.

    • So the only valid digits are arabic numbers but arabic script numbers are not a valid digit? If we want programming to be inclusive then doesn’t that make sense to also include the arabic script number?

      • ChaoticNeutralCzech ( ChaoticNeutralCzech@feddit.org ) 
        link
        fedilink
        English
        arrow-up
        18
        ·
        edit-2
        2 years ago

        So the only valid digits are arabic numbers but arabic script numbers are not a valid digit?

        Some people writing Regex implementations have that opinion. I’ve refrained from saying mine.

        If we want programming to be inclusive then doesn’t that make sense to also include the arabic script number?

        Maybe. IMO, number tests should be chosen/implemented based on the project’s requirements. If you want to include every Unicode character or string pattern anyone’s ever used to convey a numeric value, that would be a long and growing list. Arguably, it’s impossible: the word “elf” means a number if interpreted as German for “eleven” but not if interpreted as English for 🧝.

        • Yeah, but “elf” are not digits. Digits are a symbol abstracted from the language itself. Does 5 and V convey different meanings in the context of digits? And yeah, I can see why they would argue about the implementation because inclusivity is important. Especially when designing a language implementation. If you are designing it wrong, it will be very hard to extend it in the future. But for application level implementation, go nuts.

          • You are right, “elf” is a stretch, it does not make sense to parse it as a number. But in some languages, the string “15 240,5” is just how a number is written (yes, that’s a U+2009 THIN SPACE, you can’t stop me from using it as a thousand separator in German). Obviously, despite having a , on their numpads, German programmers still expect computers to parse numbers with decimal dots and interpret commas as list values.

            • bitfucker ( bitfucker@programming.dev ) 
              link
              fedilink
              arrow-up
              1
              ·
              edit-2
              2 years ago

              Alright, maybe you misunderstood the term digits with numbers. When parsing a digit, you do not attach semantic yet to the building blocks. A \d regex parser does not care that the string “555” is not equivalent to “VVV”. All it cares about is that there is the digit “5” or “V”. In the same vein, regex parser should not try to parse IV as a single symbol.

    • sushibowl ( sushibowl@feddit.nl ) 
      link
      fedilink
      arrow-up
      26
      ·
      2 years ago

      is-number is a project by John Schlinkert. John has a background in sales and marketing before he became an open source programmer and started creating these types of single function packages. So far he has about 1400 projects. Not all of them are this small, though many are.

      He builds a lot of very basic functionality packages. Get the first n values from an array. Sort an array. Set a non-enumerable property on an object. Split a string. Get the length of the longest item in an array. Check if a path ends with some string. It goes on and on.

      If you browse through it’s not uncommon to find packages that do nothing but call another package of his. For example, is-valid-path provides a function to check if a windows path contains any invalid characters. The only thing it does is import and call another package, is-invalid-path, and inverses its output.

      He has a package called alphabet that only exports an array with all the letters of the alphabet. There’s a package that provides a list of phrases that could mean “yes.” He has a package (ansi-wrap) to wrap text in ANSI color escape codes, then he has separate packages to wrap text in every color name (ansi-red, ansi-cyan, etc).

      To me, 1400 projects is just an insane number, and it’s only possible because they are all so trivial. To me, it very much looks like the work of someone who cares a lot about pumping up his numbers and looking impressive. However the JavaScript world also extolled the virtues of these types of micro packages at some point so what do I know.

      • Wow you’re right, he’s the author of the infamous “is-odd” and “is-even” packages. What an odd person.

        Someone in the OP PR mentioned the amount of energy used to download these tiny packages and its actually something crazy to think about

      • To me, 1400 projects is just an insane number, and it’s only possible because they are all so trivial.

        Holy shit. I’m going to have to go through my team’s dependencies. I don’t feel confident that someone “maintaining” that many projects is going to be able to keep all bad actors at bay. Not to mention, none of the examples of his libraries that I’ve seen SHOULD be libraries.

    • sus ( sus@programming.dev ) OP
      link
      fedilink
      arrow-up
      57
      ·
      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 ( sparkle@lemm.ee ) 
        link
        fedilink
        Cymraeg
        arrow-up
        11
        ·
        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.

      • Admiral Patrick ( ptz@dubvee.org ) 
        link
        fedilink
        English
        arrow-up
        26
        ·
        2 years ago

        Sadly, it’s a stupid dependency of a lot of things.

        Just ran npm explain is-number on one of my projects, and it’s a dependency of to-regex-range which is a dependency of fill-range which is a dependency of…and so on up the chain.

        I was hoping I wouldn’t find that in there, but alas, it is.

      • I don’t get the concept that depending on 7 lines of code from a third-party package is remotely acceptable. It’s expanding the potential attack surface to save a dev from templating 7 lines of boilerplate. There’s no net benefit or appreciable time saved.

        I’m glad I don’t have to deal with this regularly.

        ETA: The package is even MIT licensed! There’s no excuse but laziness and not wanting to understand the code to import this rather than inlining or implementing a novel version. If I can spend the time to write:

        if err != nil {
          slog.Warn("well shit", "error", err)
          return err
        }
        

        after every function call…I just didn’t get it.

    • lad ( sukhmel@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

  • 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…