• whaleross@lemmy.world
    link
    fedilink
    arrow-up
    21
    ·
    21 days ago

    People that try to do mathematical operations with strings blaming the programming language that had a stated design goal to do its best and try to keep running scripts that make no sense because they realized it would be used by people that have no idea what they are doing. Clearly they were right.

    • grue@lemmy.world
      link
      fedilink
      arrow-up
      16
      ·
      21 days ago

      the programming language that had a stated design goal to do its best and try to keep running scripts that make no sense…

      …itself makes no sense. It is wrong and bad that Javascript was ever designed that way in the first place.

      • whaleross@lemmy.world
        link
        fedilink
        arrow-up
        13
        ·
        21 days ago

        It was never intended to run full applications but only the small business scripts and hobbyist homepage stuff that were the thing in the 90s, across inconsistent browsers that were a jungle of hit and miss behaviour where it was preferred that menus keep working even if the mouse effect was not. Anything of scale was expected to be done in Java. Dynamic web pages did not exist and as anything not static was generated server side into a static html file to be rendered on the client.

        Anyway, back then it wasn’t considered the job of the programming language to hold the hand of the aspiring developer as it is common today. It’s not a bad thing that IDE and even compilers and preprocessors try to help you write better code today, but then it simply didn’t exist.

        JavaScript is from a different time and because it has the hard requirement or backwards compatibility there is no changing it and has not been for thirty years except to add stuff to it.

        I think it’s just silly to ask the past to keep up with the present. Bad code is not the fault of the language regardless, even though junior devs and even seasoned ones like to think so to protect their ego. I think it is better to accept it, learn from it and roll with it because every single platform and language has their weird quirks anyway.

        Signed, old dude that learned programming in 8 bit BASIC and 6502 machine code without an assembler, where code bad enough would freeze your machine that required a cold boot and starting over from your last save that you didn’t do.

        • raspberriesareyummy@lemmy.world
          link
          fedilink
          arrow-up
          6
          ·
          21 days ago

          Executing after undefined behavior is arguably worse than terminating with an exception. A terminated script can’t leak data or wreak havoc in other ways.

  • capybara@lemm.ee
    link
    fedilink
    English
    arrow-up
    19
    ·
    20 days ago

    To start off… Using arithmetic operators on strings in combination with integers is a pure skill issue. Let’s disregard this.

    If you were to use + where one part is a string, it’s natural to assume a string appending is desired since + is commonly used as a function for this. On the other hand, - is never used for any string operation. Therefore, it’s safe to assume that it relates to actual artihmetics and any strings should therefore be converted to numerical values.

    This is an issue with untyped languages. If you don’t like it, use typescript. End of story.

  • arc@lemm.ee
    link
    fedilink
    arrow-up
    7
    ·
    edit-2
    20 days ago

    Javascript is a dogshit language that everyone is stuck with. The best that we can hope for is the likes of typescript take the edge off of it. Even though it’s like smearing marzipan over a turd. At least it’s ok if you don’t take a deep bite.

    • Fijxu@programming.dev
      link
      fedilink
      arrow-up
      3
      ·
      20 days ago

      JS should have never leaved the Browser side. Now you can use this thing for Backend and is just awful

  • proctor1432@lemmy.world
    link
    fedilink
    arrow-up
    5
    ·
    20 days ago

    Heck, I need to learn some new languages apparently. Here I was expecting an angry "CS0029 cannot implicitly convert type ‘string’ to ‘int’!

  • kamen@lemmy.world
    link
    fedilink
    arrow-up
    3
    ·
    20 days ago

    If you’re consciously and intentionally using JavaScript like that, I don’t want to be friends with you.

  • Supervisor194@lemmy.world
    link
    fedilink
    arrow-up
    3
    ·
    edit-2
    21 days ago

    It’s not that hard to understand what it is doing and why the decision was made to make it do that. JavaScript has a particular purpose and it’s mission is not consistency.

    It’s not like TypeScript doesn’t exist if you just get lightheaded at the idea of learning JavaScript’s quirks and mastering using it despite them.

    • Shanmugha@lemmy.world
      link
      fedilink
      arrow-up
      3
      ·
      edit-2
      21 days ago

      Scanned the article: neither mission, nor purpose, nor type coercion unga-bunga explained. Or was I expected to see the greatness of the language and be humbled by its glory and might?

  • bitjunkie@lemmy.world
    link
    fedilink
    arrow-up
    2
    ·
    edit-2
    20 days ago

    It’s because + is two different operators and overloads based on the type to the left, while - is only a numeric operator and coerces left and right operands to numeric. But frankly if you’re still using + for math or string concatenation in 2025, you’re doing it wrong.

    • Hadriscus@lemm.ee
      link
      fedilink
      arrow-up
      5
      ·
      20 days ago

      I know nothing about javascript, what is wrong with using + for math? perhaps naively, I’d say it looks suited for the job