• namingthingsiseasy@programming.dev
    link
    fedilink
    arrow-up
    2
    ·
    9 hours ago

    Yeah, I’ve seen a lot of those videos where they do things like {} + [], but why would anyone care what JS does in that case? Unless you’re a shit-ass programmer, you’re never going to be running code like that.

    By this same logic, memory safety issues in C/C++ aren’t a problem either, right? Just don’t corrupt memory or dereference null pointers. Only “a shit-ass programmer” would write code that does something like that.

    Real code has complexity. Variables are written to and read from all sorts of places and if you have to audit several functions deep to make sure that every variable won’t be set to some special value like that, then that’s a liability of the language that you will always have to work around carefully.

    • hperrin@lemmy.ca
      link
      fedilink
      English
      arrow-up
      1
      ·
      1 hour ago

      No.

      By that same logic, memory safety issues in C/C++ don’t make them bad programming languages.

      If you’re worried about it, like you’re accepting input from the user, sanitize it.

      if (typeof userProvidedData !== "string") {
        throw new Error("Only works on strings.");
      }
      

      Better yet, put that in a function called assertString.