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 2 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.
  • 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.

    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
    #114

    I think it's less about type system, and more about lack of a separate compilation step.

    With a compilation step, you can have error messages that developers see, but users don't. (Hopefully, these errors enable the developers to reduce the errors that users see, and just generally improve the UX, but that's NOT guaranteed.)

    Without a compilation step, you have to assign some semantics to whatever random source string your interpreter gets. And, while you can certainly make that an error, that would rarely be helpful for the user. JS instead made the choice to, as much as possible, avoid error semantics in favor of silent coercions, conversions, and conflations in order to make every attempt to not "error-out" on the user.

    It would be a very painful decade indeed to now change the semantics for some JS source text.

    Purescript is a great option. Typescript is okay. You could also introduce a JS-to-JS "compilation" step that DID reject (or at least warn the developer) for source text that "should" be given an error semantic, but I don't know an "off-the-shelf" approach for that -- other than JSLint.

    1 Reply Last reply
    1
    • R [email protected]

      Also, you contradicted yourself just then and there. Not a single of your examples does string concatenation for these types. It's only JS

      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
      #115
      • In https://lemm.ee/comment/20947041 they claimed "implicit type coercion" and showed many examples; they did NOT claim "string concatenation".
      • However, that was in reply to https://lemmy.world/comment/17473361 which was talking about "implicit conversion to string" which is a specific type of "implicit type coercion"; NONE of the examples given involved a conversion to string.
      • But also, that was in reply to https://lemm.ee/comment/20939144 which only mentions "implicit type coercion" in general.

      So, I think probably everyone in the thread is "correct", but you are actually talking past one another.

      I think the JS behavior is a bad design choice, but it is well documented and consistent across implementations.

      R 1 Reply Last reply
      2
      • F [email protected]

        Sure, but at this point it's your own fault if you don't use Typescript to keep these issues from happening.

        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
        #116

        "Use a different language" is a common defense of javascript, but kind of a weird one.

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

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

          1 Reply Last reply
          4
          • J [email protected]

            "Use a different language" is a common defense of javascript, but kind of a weird one.

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

            Not really, considering Typescript only adds static types to JS. It's not a different language, it's an extension.

            Q 1 Reply Last reply
            4
            • R [email protected]

              Imagine doing math with strings and then blaming the language not yourself

              gmtom@lemmy.worldG This user is from outside of this forum
              gmtom@lemmy.worldG This user is from outside of this forum
              [email protected]
              wrote on last edited by
              #119

              The problem is consistency.

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

                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.

                1 Reply Last reply
                14
                • S [email protected]

                  So, all you've mustered is some lame-ass whataboutism?
                  Have a good day

                  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
                  #121

                  So you don't have a suggestion. Got it.

                  S 1 Reply Last reply
                  0
                  • supervisor194@lemmy.worldS [email protected]

                    So you don't have a suggestion. Got it.

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

                    Of course. Nothing beats JS, oh guru mighty guru

                    supervisor194@lemmy.worldS 1 Reply Last reply
                    0
                    • B [email protected]
                      • In https://lemm.ee/comment/20947041 they claimed "implicit type coercion" and showed many examples; they did NOT claim "string concatenation".
                      • However, that was in reply to https://lemmy.world/comment/17473361 which was talking about "implicit conversion to string" which is a specific type of "implicit type coercion"; NONE of the examples given involved a conversion to string.
                      • But also, that was in reply to https://lemm.ee/comment/20939144 which only mentions "implicit type coercion" in general.

                      So, I think probably everyone in the thread is "correct", but you are actually talking past one another.

                      I think the JS behavior is a bad design choice, but it is well documented and consistent across implementations.

                      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
                      #123

                      Read the thread again, it seems you slipped somewhere. This was all about the claim that implicit conversion to string somehow could make sense.

                      1 Reply Last reply
                      0
                      • B [email protected]

                        (.) is a valid expression in Haskell. Normally it is the prefix form of the infix operator . that does function
                        composition. (.) (2*) (1+) 3 = ((2*) . (1+)) 3 = 2 * (1 + 3) = 8.

                        But, the most common use of the word "boob" in my experience in Haskell is the "boobs operator": (.)(.). It's usage in Haskell is limited (tho valid), but it's appearance in racy ASCII art predates even the first versions on Haskell.

                        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
                        #124

                        The pioneers of ASCII art in the 70s and 80s are the unsung heroes of porn.

                        1 Reply Last reply
                        1
                        • S [email protected]

                          Of course. Nothing beats JS, oh guru mighty guru

                          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
                          #125

                          So all you've mustered is some lame-ass ad-hominem? Have a good day

                          S 1 Reply Last reply
                          0
                          • cm0002@lemmy.worldC [email protected]
                            This post did not contain any content.
                            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
                            #126

                            It's my favorite language too, but I also find this hilarious.

                            1 Reply Last reply
                            1
                            • S [email protected]

                              So, just don’t use JavaScript?

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

                              That's also my understanding: "Javascript is great because you can use other languages and then transpile them to JS."

                              K F 2 Replies Last reply
                              6
                              • 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]
                                #128

                                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.

                                H 1 Reply Last reply
                                5
                                • B [email protected]

                                  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.

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

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

                                  Q _ B 3 Replies Last reply
                                  6
                                  • cm0002@lemmy.worldC [email protected]
                                    This post did not contain any content.
                                    calavera@lemmy.zipC This user is from outside of this forum
                                    calavera@lemmy.zipC This user is from outside of this forum
                                    [email protected]
                                    wrote on last edited by
                                    #130

                                    It makes sense though

                                    Q Z P 3 Replies Last reply
                                    8
                                    • H [email protected]

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

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

                                      It's much better to make your own function that uses bitwise operations to do addition.

                                      function add(a, b) {
                                          while (b !== 0) {
                                              // Calculate carry
                                              let carry = a & b;
                                      
                                              // Sum without carry
                                              a = a ^ b;
                                      
                                              // Shift carry to the left
                                              b = carry << 1;
                                          }
                                          return a;
                                      }
                                      

                                      (For certain definitions of better.)

                                      1 Reply Last reply
                                      5
                                      • F [email protected]

                                        Not really, considering Typescript only adds static types to JS. It's not a different language, it's an extension.

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

                                        Since it needs to be compiled to JavaScript in order to be used, I kind of consider it a different language. Yes, it's a strict superset of JavaScript, but that makes it different.

                                        F 1 Reply Last reply
                                        5
                                        • D [email protected]

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

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

                                          Better than doing physics with strings

                                          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