Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo

agnos.is Forums

  1. Home
  2. Programmer Humor
  3. JavaScript

JavaScript

Scheduled Pinned Locked Moved Programmer Humor
programmerhumor
152 Posts 83 Posters 3 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S [email protected]

    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?

    supervisor194@lemmy.worldS This user is from outside of this forum
    supervisor194@lemmy.worldS This user is from outside of this forum
    [email protected]
    wrote on last edited by
    #53

    Well then, rage against the machine for the next 30 years and see if they kill it in favor of a nice, strict language that everybody loves. Maybe you could suggest one here for consideration.

    S 1 Reply Last reply
    0
    • P [email protected]

      Given it's JavaScript, which was expressly designed to carry on regardless, I could see an argument for it returning NaN, (or silently doing what Perl does, like I mention in a different comment) but then there'd have to be an entirely different way of concatenating strings.

      R This user is from outside of this forum
      R This user is from outside of this forum
      [email protected]
      wrote on last edited by
      #54

      Why would you need an entirely different way of concatenating strings? "11" + 1 -> exception. "11" + to_string(1) = "111"

      P 1 Reply Last reply
      0
      • whaleross@lemmy.worldW [email protected]

        Now that you mention it, it is a bit funny how Lemmy is hating LLMs as a code generation tool while also hating on the interpreter for their own hand typed code not running.

        I This user is from outside of this forum
        I This user is from outside of this forum
        [email protected]
        wrote on last edited by
        #55

        I mean, in both cases it's because the LLM and interpreter do things you wouldn't expect.

        1 Reply Last reply
        2
        • cm0002@lemmy.worldC [email protected]
          This post did not contain any content.
          B This user is from outside of this forum
          B This user is from outside of this forum
          [email protected]
          wrote on last edited by [email protected]
          #56

          This is my favorite language: GHC Haskell

          GHC Haskell:

          GHCi> length (2, "foo")
          1
          
          Y 1 Reply Last reply
          8
          • S [email protected]

            Especially that + and - act differently. If + does string concattenation, - should also do some string action or throw an error in this situation.

            R This user is from outside of this forum
            R This user is from outside of this forum
            [email protected]
            wrote on last edited by
            #57
            • should also do some string action

            Like what kind of string action?

            "Hello" + " world" is what everyone can understand. Switch with "-" and it becomes pointless.

            pupbiru@aussie.zoneP 1 Reply Last reply
            3
            • B [email protected]

              This is my favorite language: GHC Haskell

              GHC Haskell:

              GHCi> length (2, "foo")
              1
              
              Y This user is from outside of this forum
              Y This user is from outside of this forum
              [email protected]
              wrote on last edited by
              #58

              Wait, now I need to know why.

              * some time later *

              I went to check why the hell this happened. It looks like the pair ("(,)") is defined as an instance of Foldable, for some reason, which is the class used by functions like foldl() and foldr(). Meanwhile, triples and other tuples of higher order (such as triples, quadruples, ...) are not instances of Foldable.

              The weirdest part is that, if you try to use a pair as a Foldable, you only get the second value, for some reason... Here is an example.

              ghci> foldl (\acc x -> x:acc) [] (1,2)
              
              [2]
              

              This makes it so that the returned length is 1.

              B L 2 Replies Last reply
              4
              • R [email protected]

                BS. A language shouldn't have operators that allow non sensical operations like string concatenation when one operand is not a string.

                3 This user is from outside of this forum
                3 This user is from outside of this forum
                [email protected]
                wrote on last edited by
                #59

                It's not nonsensical, implicit type coercion is a feature of JavaScript, it's perfectly logical and predictable.

                JavaScript is a filthy beast, it's not the right tool for every job, but it's not nonsensical.

                When you follow a string with a +, it concatenates it with the next value (converted to string if needed). This makes sense, and it's a very standard convention in most languages.

                Applying arithmetic to a string would be nonsensical, which they don't do.

                R 1 Reply Last reply
                7
                • R [email protected]

                  Why would you need an entirely different way of concatenating strings? "11" + 1 -> exception. "11" + to_string(1) = "111"

                  P This user is from outside of this forum
                  P This user is from outside of this forum
                  [email protected]
                  wrote on last edited by
                  #60

                  You're right. I've got too much Perl on the brain and forgot my roots. There is a language that does what you're talking about with the '+' operator: BASIC

                  Good luck getting the same thing retrofitted into JavaScript though. I can imagine a large number of websites would break or develop mysterious problems if this (mis)behaviour was fixed.

                  R 1 Reply Last reply
                  0
                  • cm0002@lemmy.worldC [email protected]
                    This post did not contain any content.
                    C This user is from outside of this forum
                    C This user is from outside of this forum
                    [email protected]
                    wrote on last edited by
                    #61

                    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.

                    J 1 Reply Last reply
                    25
                    • W [email protected]

                      This has got to be baNaNa

                      C This user is from outside of this forum
                      C This user is from outside of this forum
                      [email protected]
                      wrote on last edited by [email protected]
                      #62

                      That is absolutely (n > 1) * ("ba" + 0/0 + "a")

                      M 1 Reply Last reply
                      2
                      • C This user is from outside of this forum
                        C This user is from outside of this forum
                        [email protected]
                        wrote on last edited by
                        #63

                        expressly designed to carry on regardless

                        I'm surprised they didn't borrow On Error Resume Next from Visual Basic. Which was wrongly considered to be the worst thing in Visual Basic - when the real worst thing was On Error Resume. On Error Resume Next at least moved on to the next line of code when an error occurred; On Error Resume just executed the error-generating line again ... and again ... and again ... and again ...

                        1 Reply Last reply
                        2
                        • C [email protected]

                          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.

                          J This user is from outside of this forum
                          J This user is from outside of this forum
                          [email protected]
                          wrote on last edited by
                          #64

                          Instead of trying to make it work, javascript could just say "error." Being untyped doesn't mean you can't have error messages.

                          C B 2 Replies Last reply
                          27
                          • J [email protected]

                            Instead of trying to make it work, javascript could just say "error." Being untyped doesn't mean you can't have error messages.

                            C This user is from outside of this forum
                            C This user is from outside of this forum
                            [email protected]
                            wrote on last edited by
                            #65

                            This is fair enough from an idealistic view. In practice, you don't want your entire website to shit itself because of a potentially insignificant error.

                            J K R V 4 Replies Last reply
                            11
                            • Y [email protected]

                              Wait, now I need to know why.

                              * some time later *

                              I went to check why the hell this happened. It looks like the pair ("(,)") is defined as an instance of Foldable, for some reason, which is the class used by functions like foldl() and foldr(). Meanwhile, triples and other tuples of higher order (such as triples, quadruples, ...) are not instances of Foldable.

                              The weirdest part is that, if you try to use a pair as a Foldable, you only get the second value, for some reason... Here is an example.

                              ghci> foldl (\acc x -> x:acc) [] (1,2)
                              
                              [2]
                              

                              This makes it so that the returned length is 1.

                              B This user is from outside of this forum
                              B This user is from outside of this forum
                              [email protected]
                              wrote on last edited by
                              #66

                              Oddly enough, in Haskell (as defined by the report), length is monomorphic, so it just doesn't work on tuples (type error).

                              Due to the way kinds (types of types) work in Haskell, Foldable instances can only operate over (i.e. length only counts) elements of the last/final type argument. So, for (,) it only counts the second part, which is always there exactly once. If you provided a Foldable for (,,,) it would also have length of 1.

                              1 Reply Last reply
                              3
                              • cm0002@lemmy.worldC [email protected]
                                This post did not contain any content.
                                P This user is from outside of this forum
                                P This user is from outside of this forum
                                [email protected]
                                wrote on last edited by
                                #67

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

                                1 Reply Last reply
                                4
                                • R [email protected]
                                  • should also do some string action

                                  Like what kind of string action?

                                  "Hello" + " world" is what everyone can understand. Switch with "-" and it becomes pointless.

                                  pupbiru@aussie.zoneP This user is from outside of this forum
                                  pupbiru@aussie.zoneP This user is from outside of this forum
                                  [email protected]
                                  wrote on last edited by
                                  #68

                                  this the “or throw an error”

                                  R 1 Reply Last reply
                                  0
                                  • gsus4@mander.xyzG [email protected]

                                    Hm, playing devil's advocate, I think it is because the minus has not been defined as a string operation (e.g. it could pop the last char), so it defaults to the mathematical operation and converts both inputs into ints.

                                    The first is assumed to be a concat because one of the parcels is a string...

                                    It's just doing a lot of stuff for you that it shouldn't be in first place 🤭

                                    D This user is from outside of this forum
                                    D This user is from outside of this forum
                                    [email protected]
                                    wrote on last edited by
                                    #69

                                    Yeah, this looks dumb on the surface, but you've got bigger problems if you're trying to do math with strings

                                    K 1 Reply Last reply
                                    8
                                    • Y [email protected]

                                      Wait, now I need to know why.

                                      * some time later *

                                      I went to check why the hell this happened. It looks like the pair ("(,)") is defined as an instance of Foldable, for some reason, which is the class used by functions like foldl() and foldr(). Meanwhile, triples and other tuples of higher order (such as triples, quadruples, ...) are not instances of Foldable.

                                      The weirdest part is that, if you try to use a pair as a Foldable, you only get the second value, for some reason... Here is an example.

                                      ghci> foldl (\acc x -> x:acc) [] (1,2)
                                      
                                      [2]
                                      

                                      This makes it so that the returned length is 1.

                                      L This user is from outside of this forum
                                      L This user is from outside of this forum
                                      [email protected]
                                      wrote on last edited by [email protected]
                                      #70

                                      I don't even know Haskell but it seems like (" ( , ) ") would be an instance of boob.

                                      D B 2 Replies Last reply
                                      0
                                      • C [email protected]

                                        This is fair enough from an idealistic view. In practice, you don't want your entire website to shit itself because of a potentially insignificant error.

                                        J This user is from outside of this forum
                                        J This user is from outside of this forum
                                        [email protected]
                                        wrote on last edited by
                                        #71

                                        In practice runtime errors are a bitch to find and fix.

                                        C 1 Reply Last reply
                                        7
                                        • pupbiru@aussie.zoneP [email protected]

                                          this the “or throw an error”

                                          R This user is from outside of this forum
                                          R This user is from outside of this forum
                                          [email protected]
                                          wrote on last edited by
                                          #72

                                          If you try what I wrote it will throw a NaN. I was asking about the first part of the proposal.

                                          S 1 Reply Last reply
                                          1
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups