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 147 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.
  • psaldorn@lemmy.worldP [email protected]

    If there's only two options you only need one keyword

    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 [email protected]
    #61

    True, but var and let are not same in js, so there is three.

    if(true) {

    var a = "dumdum"

    }

    console.log(a)

    Is valid and functioning javascript. With let it is not.

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

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

      At least in C#, you can define variables with keyword names like this:

      var @struct = "abc"

      I think in Kotlin you can do the same, and even include spaces with backticks like val abstract class = "abc"

      I'm not sure if other languages allow that, regardless it should be rarely used.

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

        It's commonly used in math to declare variables so I assume programming languages borrowed it from there.

        chaos@beehaw.orgC This user is from outside of this forum
        chaos@beehaw.orgC This user is from outside of this forum
        [email protected]
        wrote on last edited by
        #63

        More specifically, they're borrowing the more mathematical meaning of variables, where if you say x equals 5, you can't later say x is 6, and where a statement like "x = x + 1" is nonsense. Using "let" means you're setting the value once and that's what it's going to remain as long as it exists, while "var" variables can be changed later. Functional languages, which are usually made by very math-y people, will often protest the way programmers use operators by saying that = is strictly for equality and variable assignment is := instead of == and = in most C-style languages.

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

          let a: &'static str

          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 [email protected]
          #64

          Rust is verbose, but C++ might still take the cake with its standard library templates. Especially when using fully-qualified type names...

          auto a = ::std::make_shared<::std::basic_string<char, ::std::char_traits<char>, MyAllocator<char>>>();

          A reference-counted shared pointer to a string of unspecified character encoding and using a non-default memory allocator.

          C theacharnian@lemmy.caT J 3 Replies Last reply
          17
          • A [email protected]

            At least in C#, you can define variables with keyword names like this:

            var @struct = "abc"

            I think in Kotlin you can do the same, and even include spaces with backticks like val abstract class = "abc"

            I'm not sure if other languages allow that, regardless it should be rarely used.

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

            Swift also uses backticks and Rust has a dumb one in the form of r#thekeyword. Still much better than introducing a async as a new keyword in a minor version of a language and breaking a bunch of libraries.

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

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

              TypeScript [...] only adds syntax, and doesn't re-write it.

              I believe enum, const enum, and decorators would like to have a word with you.

              1 Reply Last reply
              2
              • I [email protected]

                I wish the interpreter cared about assignment

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

                Dude, even just a "FY,I, you sure about this?" would be nice. I gladly embrace python's by-all-means-shotgun-your-leg-off philosophy, but the noobs could use the help.

                lime@feddit.nuL 1 Reply Last reply
                5
                • 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.

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

                  I believe the reason a function or method in an object does not need the “function” keyword has to do with the fact that JS is built on the prototype model and the fact that functions are first class in JS.

                  As the saying goes, “Everything is an object in JavaScript…” (which is not strictly true).

                  1 Reply Last reply
                  0
                  • chaos@beehaw.orgC [email protected]

                    More specifically, they're borrowing the more mathematical meaning of variables, where if you say x equals 5, you can't later say x is 6, and where a statement like "x = x + 1" is nonsense. Using "let" means you're setting the value once and that's what it's going to remain as long as it exists, while "var" variables can be changed later. Functional languages, which are usually made by very math-y people, will often protest the way programmers use operators by saying that = is strictly for equality and variable assignment is := instead of == and = in most C-style languages.

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

                    Unless you’re in JS.

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

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

                      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]
                      #70

                      The actual reason why let ... in syntax tends to not use C-style "type var" like syntax is because it's derived from the syntax type theory uses, and type theorists know about parameterised types. Generics, in C++ parlance, excuse my Haskell:

                      let foo :: Map Int String = mempty

                      We have an empty map, and it maps integers to Strings. We call it foo. Compare:

                      Map Int String foo = mempty

                      If nothing else, that's just awkward to read and while it may be grammatically unambiguous (a token is a name if it sits directly in front of =) parser error messages are going to suck. Map<Int,String> is also awkward but alas that's what we're stuck with in Rust because they reasoned that it would be cruel to put folks coming from C++ on angle bracket withdrawal. Also Rust has ML ancestry don't get me started on their type syntax.

                      W U hiddenlayer555@lemmy.mlH 3 Replies Last reply
                      26
                      • J [email protected]

                        Then the second part of my statement applies.

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

                        In the case of Rust, you can also omit the type annotation in the vast majority of cases and the compiler will infer it.

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

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

                          Good, now invent a keyword for variables you don't want to declare the type.

                          auto. Also in D, you only need const if you don't want to specify a type for a constant, the compiler automatically inferres it to you.

                          Function declarations can be easily decyphered from context, no problem.

                          U 1 Reply Last reply
                          3
                          • L [email protected]

                            I think you can do const thing = ... as constto lock down the mutation?

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

                            So is let in some languages. In Rust, you have to constantly opt out from immutability with let mut, which makes writing more procedural code feel like you're fighting with the compiler, and otherwise I don't really see the rationale behind full functional coding. I only had a bug caused only once by unwanted mutation, the hardest part fixing it was to learn the proper use of my debugger tool.

                            1 Reply Last reply
                            2
                            • embed_me@programming.devE [email protected]

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

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

                              The basic problem is that identifiers can be either types or variables, and without a keyword letting you know what kind of statement you're dealing with, there's no way of knowing without a complete identifier table. For example, what does this mean:

                              foo * bar;
                              

                              If foo is a type, that is a pointer declaration. But if it's a variable, that's a multiplication expression. Here's another simple one:

                              foo(bar);
                              

                              Depending on how foo is defined, that could be a function call or a declaration of a variable bar of type foo, with some meaningless parentheses thrown in.

                              When you mix things together it gets even more crazy. Check this example from this article:

                              foo(*bar)();
                              
                              

                              Is bar a pointer to a function returning foo, or is foo a function that takes a bar and returns a function pointer?

                              let and fn keywords solve a lot of these ambiguity problems because they let the parser know what kind of statement it's looking at, so it can know whether identifiers in certain positions refer to types or variables. That makes parsing easier to write and helps give nicer error messages.

                              B 1 Reply Last reply
                              17
                              • P [email protected]

                                Javascript gonna Javascript

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

                                JavaScript* 👍

                                P 1 Reply Last reply
                                0
                                • 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.

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

                                  Type inference is a pretty big thing in TypeScript as well though. In fact it's probably the biggest thing about it, IMO.

                                  C 1 Reply Last reply
                                  0
                                  • W [email protected]

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

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

                                    I would because I know TypeScript and I don't know Rust.

                                    W 1 Reply Last reply
                                    0
                                    • hiddenlayer555@lemmy.mlH [email protected]

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

                                      glorkon@lemmy.worldG This user is from outside of this forum
                                      glorkon@lemmy.worldG This user is from outside of this forum
                                      [email protected]
                                      wrote on last edited by
                                      #78
                                      IT'S SHOWTIME
                                        I NEED YOUR CLOTHES YOUR BOOTS AND YOUR MOTORCYCLE a
                                        GET TO THE CHOPPER a
                                          HERE IS MY INVITATION "ArnoldC is the best."
                                        ENOUGH TALK
                                        TALK TO THE HAND a
                                      YOU HAVE BEEN TERMINATED
                                      
                                      1 Reply Last reply
                                      18
                                      • B [email protected]

                                        The actual reason why let ... in syntax tends to not use C-style "type var" like syntax is because it's derived from the syntax type theory uses, and type theorists know about parameterised types. Generics, in C++ parlance, excuse my Haskell:

                                        let foo :: Map Int String = mempty

                                        We have an empty map, and it maps integers to Strings. We call it foo. Compare:

                                        Map Int String foo = mempty

                                        If nothing else, that's just awkward to read and while it may be grammatically unambiguous (a token is a name if it sits directly in front of =) parser error messages are going to suck. Map<Int,String> is also awkward but alas that's what we're stuck with in Rust because they reasoned that it would be cruel to put folks coming from C++ on angle bracket withdrawal. Also Rust has ML ancestry don't get me started on their type syntax.

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

                                        There is also the thing where the compiler might mistake your c++ style variable declaration for a function, e.g.

                                        String myfunction():

                                        String myvariable();

                                        1 Reply Last reply
                                        7
                                        • V [email protected]

                                          Type inference is a pretty big thing in TypeScript as well though. In fact it's probably the biggest thing about it, IMO.

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

                                          I don't know typescript. But if that's the case, this meme doesn't make much sense.

                                          Who writes the types of variables in a language with type inference unless forced by the compiler?

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