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. Why make it complicated?

Why make it complicated?

Scheduled Pinned Locked Moved Programmer Humor
programmerhumor
116 Posts 58 Posters 164 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.
  • dan@upvote.auD [email protected]

    Can we talk about PHP functions with typehints too?

    public static function foo(): string {
    

    Practically every other language with similar syntax does this instead:

    public static string foo() {
    
    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
    #41

    JavaScript (Typescript for the type part) and python, the most popular scripting languages, use the same order as PHP.

    It's usually compiled languages that do the other one.

    dan@upvote.auD 1 Reply Last reply
    1
    • M [email protected]

      That looks like rust ngl

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

      It's also valid rust syntax.

      But if it were rust, this meme would not make sense, since you would just type let a and type inference would do its thing. Which is much more ergonomic.

      N V 2 Replies Last reply
      13
      • hiddenlayer555@lemmy.mlH [email protected]

        Made with KolourPaint and screenshots from Kate (with the GitHub theme).

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

        Javascript gonna Javascript

        V 1 Reply Last reply
        3
        • M [email protected]

          Good, now invent a keyword for variables you don't want to declare the type. And now that you have a mix of keywords and identifiers on the same place, you can never update your language again.

          Also, make the function declarations not use a keyword too, so you get the full C-style madness of code that changes meaning depending on what libraries you import.

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

          I don't understand how not using a keyword to define a function causes the meaning to change depending on imports. I've never run into an issue like that before. Can you give an example?

          M 1 Reply Last reply
          17
          • S [email protected]

            So I think it's still probably unclear to people why "mix of keywords and identifiers" is bad: it means any new keyword could break backwards compatibility because someone could have already named a type the same thing as that new keyword.

            This syntax puts type identifiers in the very prominent position of "generic fresh statement after semicolon or newline"

            ..though I've spent like 10 minutes thinking about this and now it's again not making sense to me. Isn't the very common plain "already_existing_variable = 5" also causing the same problem? We'd have to go back to cobol style "SET foo = 5" for everything to actually make it not an issue

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

            Ah I was misunderstanding the problem. And learned something new about C#, seems in order to avoid breaking existing code they introduce "contextual keywords" var being added later, it is a contextual. You can create a class 'var' and the compiler will prefer it.

            1 Reply Last reply
            4
            • C [email protected]

              It's also valid rust syntax.

              But if it were rust, this meme would not make sense, since you would just type let a and type inference would do its thing. Which is much more ergonomic.

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

              let a = String::from(“Hello, world!”).into()

              I’ll see myself out.

              A 1 Reply Last reply
              6
              • C [email protected]

                JavaScript (Typescript for the type part) and python, the most popular scripting languages, use the same order as PHP.

                It's usually compiled languages that do the other one.

                dan@upvote.auD This user is from outside of this forum
                dan@upvote.auD This user is from outside of this forum
                [email protected]
                wrote on last edited by
                #47

                TypeScript doesn't need the "function" keyword for a method in an object or on a class though.

                const foo = {
                  bar(): string {
                   ... 
                  } 
                }
                

                which I assume is doable because the syntax is unambiguous.

                In PHP's case, the method syntax should also be unambiguous.

                1 Reply Last reply
                1
                • M [email protected]

                  That looks like rust ngl

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

                  I was thinking the same thing. who would write typescript if they could just do Rust?

                  V 1 Reply Last reply
                  4
                  • dan@upvote.auD [email protected]

                    It enforces scalar types (string, int, etc) at runtime if you enable strict mode. There's also static analysis tools like PHPStan and Psalm that will flag issues at build time.

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

                    so, no. good catch OP!

                    1 Reply Last reply
                    0
                    • beigeagenda@lemmy.caB [email protected]

                      And then assign an int to a string just to mess with the interpreter.

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

                      I wish the interpreter cared about assignment

                      _ 1 Reply Last reply
                      5
                      • J [email protected]

                        Not to short-circuit the joke, but in this case, it's because the valid JavaScript version is...

                        let a
                        

                        ...and one of TypeScript's main design goals is to be a superset of JavaScript, that only adds syntax, and doesn't re-write it.

                        Beyond that, it's probably a case of some new language just using what the designer is familiar with.

                        zea_64@lemmy.blahaj.zoneZ This user is from outside of this forum
                        zea_64@lemmy.blahaj.zoneZ This user is from outside of this forum
                        [email protected]
                        wrote on last edited by
                        #51

                        Who says this is JS? Might be Rust.

                        J 1 Reply Last reply
                        2
                        • hiddenlayer555@lemmy.mlH [email protected]

                          Made with KolourPaint and screenshots from Kate (with the GitHub theme).

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

                          String a: new String()

                          1 Reply Last reply
                          14
                          • S [email protected]

                            I don't understand how not using a keyword to define a function causes the meaning to change depending on imports. I've never run into an issue like that before. Can you give an example?

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

                            Some declarations terminate on the name, other declarations go one requiring more tokens. In C, the only thing that differentiates them is the type.

                            Parenthesis in particular are completely ambiguous. But asterisks and square brackets also create problems.

                            embed_me@programming.devE 1 Reply Last reply
                            14
                            • zea_64@lemmy.blahaj.zoneZ [email protected]

                              Who says this is JS? Might be Rust.

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

                              Then the second part of my statement applies.

                              E 1 Reply Last reply
                              2
                              • dan@upvote.auD [email protected]

                                TypeScript doesn't need the "function" keyword for a method in an object or on a class though.

                                const foo = {
                                  bar(): string {
                                   ... 
                                  } 
                                }
                                

                                which I assume is doable because the syntax is unambiguous.

                                PHP's object orientation is similar to languages like Java and C#, which is what I was comparing to.

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

                                Your example didn't mention the use of the function keyword. Instead, it seemed to be questioning the placement of the return type - placing it after the argument list seems pretty common in newer languages.

                                1 Reply Last reply
                                0
                                • frostypolicy@suppo.fiF [email protected]

                                  And Kotlin.

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

                                  AND MY AXE!

                                  1 Reply Last reply
                                  3
                                  • _ [email protected]

                                    python:

                                    a: str = 1

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

                                    That's just a comment

                                    Z 1 Reply Last reply
                                    3
                                    • hiddenlayer555@lemmy.mlH [email protected]

                                      Made with KolourPaint and screenshots from Kate (with the GitHub theme).

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

                                      let a: &'static str

                                      P 1 Reply Last reply
                                      16
                                      • M [email protected]

                                        Some declarations terminate on the name, other declarations go one requiring more tokens. In C, the only thing that differentiates them is the type.

                                        Parenthesis in particular are completely ambiguous. But asterisks and square brackets also create problems.

                                        embed_me@programming.devE This user is from outside of this forum
                                        embed_me@programming.devE This user is from outside of this forum
                                        [email protected]
                                        wrote on last edited by
                                        #59

                                        I have never heard of this problem for C. Can you elaborate or point to some articles?

                                        S 1 Reply Last reply
                                        2
                                        • G [email protected]

                                          You're encoding more information in the typescript one. You're saying it's a string that will get updated.

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

                                          C# has const string a = "Hello, World";

                                          var in js is legacy, and default should be let, but changing that would break everything

                                          1 Reply Last reply
                                          2
                                          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