• AbsolutelyNotCats@lemdro.id
    link
    fedilink
    English
    arrow-up
    48
    ·
    edit-2
    10 months ago

    Just a reminder that JavaScript was developed in 10 days, the same amount of time i spend fixing bugs when i just miss a “,”

    • Rikudou_Sage@lemmings.world
      link
      fedilink
      arrow-up
      38
      arrow-down
      5
      ·
      10 months ago

      Has anyone actually read through that? Reading the first few examples and it’s just not understanding how languages work half of the time:

      !!"false" == !!"true"; // -> true
      !!"false" === !!"true"; // -> true
      

      Wow, no shit, non-empty string coerces to true, who would’ve guessed! Did you know that !!"bullshit" === !!"true" as well? Mind=blown.

      NaN === NaN; // -> false
      

      Again, no shit, that’s in the NaN specification and the page even mentions it, so why even include it?

      • noli@programming.dev
        link
        fedilink
        arrow-up
        22
        ·
        10 months ago

        Which is why I’m of the opinion that dynamically typed languages are evil. !!“false” should either be caught at compile time or raise an exception.

        I’m thoroughly convinced that the only use of dynamically typed languages is to introduce bugs

        • Rikudou_Sage@lemmings.world
          link
          fedilink
          English
          arrow-up
          2
          arrow-down
          1
          ·
          10 months ago

          Why? IMO that’s perfectly valid. The various type coercions are sometimes crazy, but IMO the rule that non-empty string is coerced to true and empty string to false is very simple to follow. The snippet is not even a gotcha, I don’t see anything worth failing over. Putting “true” or “false” in a string doesn’t change that.

          • noli@programming.dev
            link
            fedilink
            arrow-up
            6
            arrow-down
            1
            ·
            edit-2
            10 months ago

            I am dumb. The more things I need to think about when reading code that is not the logic of the code, the worse it is. Any time I have to spend thinking about the peculiarities of the way the language handles something is time wasted.

            I’ll give a very simple example, think like you’re trying to find a bug. Assume we’re in a dynamic language that allows implicit conversion like this. We can write our code very “cleanly” as follows:

            if(!someVar) doSomething();

            -> ok, now we gotta check where someVar’s value is last set to know what type of data this is. Then I need to remember or look up how those specific types are coerced into a bool.

            When trying the same code in a statically typed language that doesn’t do implicit coercion that code will fail to run/compile so probably you’ll have something like this:

            if(someVar.length() == 0) doSomething();

            -> this time I can just look at the type of someVar to see it’s a string and it’s clear what the condition actually means.

            The second option is both easier to read and less bug prone even without the type system. It takes maybe 3 seconds longer to type, but if your productivity in coding is that limited by typing speed then I envy you

      • icesentry@programming.dev
        link
        fedilink
        arrow-up
        1
        ·
        10 months ago

        Also, a huge proportion of the list is just not understanding IEEE floats behaviour and blaming the language for it. Exactly like this post is doing. All those weird number things js does is because it only uses floats for everything and every language that uses floats will behave the exact same way.

    • MonkderZweite@feddit.ch
      link
      fedilink
      arrow-up
      1
      ·
      10 months ago

      So, uh, first example, the developer decided instead of comparing based on type, he rather converts the values? Why?!