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 162 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]

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

    I feel this is related, and hightlight this even further, look at all the ways to initialize something in C++.

    https://www.youtube.com/watch?v=7DTlWPgX6zs

    If you are really lazy, have a look at making an int at around 7:20. It's not horrible that alone, but it does show how many meanings each thing has with very little difference, added on top of years of legacy compatability accumulation. Then it further goes into detail about the auto use, and how parantheses, bracket, squiggly bracket all can be used and help with the mess.

    1 Reply Last reply
    1
    • P [email protected]

      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.

      theacharnian@lemmy.caT This user is from outside of this forum
      theacharnian@lemmy.caT This user is from outside of this forum
      [email protected]
      wrote on last edited by
      #83

      I don't understand why verbose is bad. Verbose is maintainable.

      K 1 Reply Last reply
      1
      • theacharnian@lemmy.caT [email protected]

        I don't understand why verbose is bad. Verbose is maintainable.

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

        Not when taken to such an extreme so as to obfuscate the meaning and behavior of code, and make it difficult to understand how you would arrive at that code.

        Sane defaults serve to reduce verbosity without obfuscating meaning, simpler syntax with different ordering and fewer tokens reduce verbosity to make the code easier to read by reducing the amount of text you have to pay attention to to understand what the result is.

        I imagine there's also a distinction to be made between verbosity and redundancy - sometimes extra text might fail to carry information, or carry information that's already carried elsewhere. I'm not sure where the line should be drawn, because sometimes duplicate information can be helpful, and spacing out information with technically meaningless text has value for readability, but I feel like it's there.

        theacharnian@lemmy.caT 1 Reply Last reply
        11
        • V [email protected]

          JavaScript* 👍

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

          Blame my phone's autocorrect

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

            Blame my phone's autocorrect

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

            Weird, my phone gave me the correct capitalization when I just used the swipe typing.

            1 Reply Last reply
            1
            • C [email protected]

              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 This user is from outside of this forum
              V This user is from outside of this forum
              [email protected]
              wrote on last edited by
              #87

              Maybe it's a language without type interference?

              Either way, it sometimes makes sense in TypeScript to help the type system out a little bit.

              let array: string[] = [];
              

              In this situation, the type system can't infer that the empty array should be a string array, because there are no items to go by.

              1 Reply Last reply
              0
              • K [email protected]

                Not when taken to such an extreme so as to obfuscate the meaning and behavior of code, and make it difficult to understand how you would arrive at that code.

                Sane defaults serve to reduce verbosity without obfuscating meaning, simpler syntax with different ordering and fewer tokens reduce verbosity to make the code easier to read by reducing the amount of text you have to pay attention to to understand what the result is.

                I imagine there's also a distinction to be made between verbosity and redundancy - sometimes extra text might fail to carry information, or carry information that's already carried elsewhere. I'm not sure where the line should be drawn, because sometimes duplicate information can be helpful, and spacing out information with technically meaningless text has value for readability, but I feel like it's there.

                theacharnian@lemmy.caT This user is from outside of this forum
                theacharnian@lemmy.caT This user is from outside of this forum
                [email protected]
                wrote on last edited by [email protected]
                #88

                Frankly, I have way more often ended up scratching my head for some cryptic piece of syntax than the opposite. Sure I could sit down and spend the rest of my life learning each language designer's favourite syntax optimisations, but I kinda don't want to. I'm a human, not a parser.

                And frankly, a good IDE editor should be able to fold/unfold verbose syntax. Better for it then to be there and folded, than for it to not be there and for someone to have to work backwards the intendrd meaning of every single line of code.

                1 Reply Last reply
                1
                • N [email protected]

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

                  I’ll see myself out.

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

                  At least be fair and cut out the .into()

                  N 1 Reply Last reply
                  3
                  • A [email protected]

                    At least be fair and cut out the .into()

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

                    And bow to the compiler’s whims? I think not!

                    This shouldn’t compile, because .into needs the type from the left side and let needs the type from the right side.

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

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

                      Until now, I looked at let and thought, "maybe they just felt like doing it that way".
                      Makes a lot more sense now.

                      1 Reply Last reply
                      1
                      • Z [email protected]

                        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 This user is from outside of this forum
                        U This user is from outside of this forum
                        [email protected]
                        wrote on last edited by
                        #92

                        Maybe that's what the people developing spoken languages thought, while normalising conversations overdependent on context.

                        But hey, now we have another comedic tool in anime.

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

                          hiddenlayer555@lemmy.mlH This user is from outside of this forum
                          hiddenlayer555@lemmy.mlH This user is from outside of this forum
                          [email protected]
                          wrote on last edited by [email protected]
                          #93

                          How do you do nested parameterized types without it becoming ambiguous though? That's IMO the biggest advantage of the bracket syntax. For example: Map<Tuple<Int, Int, Int> Int>

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

                            hiddenlayer555@lemmy.mlH This user is from outside of this forum
                            hiddenlayer555@lemmy.mlH This user is from outside of this forum
                            [email protected]
                            wrote on last edited by [email protected]
                            #94

                            any new keyword could break backwards compatibility

                            Wouldn't that happen anyway with variable and function names? Any type other than primitive/built in ones are usually camel case so lower case keywords are more likely to clash with single word variable and function names, unless you restrict the cases of those too or allow keyword overriding or something.

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

                              How do you do nested parameterized types without it becoming ambiguous though? That's IMO the biggest advantage of the bracket syntax. For example: Map<Tuple<Int, Int, Int> Int>

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

                              Map (Int, Int) Int. Kind of a bad example because tuples have special-case infix syntax, the general case would be Map Int (Either Int Bool). Follows the same exact syntax as function application just that types (by enforced convention) start upper case. Modulo technical wibbles to ensure that type inference is possible you can consider type constructors to be functions from types to types.

                              ...function application syntax is a story in itself in Haskell because foo a b c gets desugared to (((foo a) b) c): There's only one-argument functions. If you want to have more arguments, accept an argument and return a function that accepts yet another argument. Then hide all that under syntactic sugar so that it looks innocent. And, of course, optimise it away when compiling. Thus you can write stuff like map (+5) xs in Haskell while other languages need the equivalent of map (\x -> x + 5) xs (imagine the \ is a lambda symbol).

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

                                Map (Int, Int) Int. Kind of a bad example because tuples have special-case infix syntax, the general case would be Map Int (Either Int Bool). Follows the same exact syntax as function application just that types (by enforced convention) start upper case. Modulo technical wibbles to ensure that type inference is possible you can consider type constructors to be functions from types to types.

                                ...function application syntax is a story in itself in Haskell because foo a b c gets desugared to (((foo a) b) c): There's only one-argument functions. If you want to have more arguments, accept an argument and return a function that accepts yet another argument. Then hide all that under syntactic sugar so that it looks innocent. And, of course, optimise it away when compiling. Thus you can write stuff like map (+5) xs in Haskell while other languages need the equivalent of map (\x -> x + 5) xs (imagine the \ is a lambda symbol).

                                hiddenlayer555@lemmy.mlH This user is from outside of this forum
                                hiddenlayer555@lemmy.mlH This user is from outside of this forum
                                [email protected]
                                wrote on last edited by [email protected]
                                #96

                                Interesting. Thanks!

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

                                  any new keyword could break backwards compatibility

                                  Wouldn't that happen anyway with variable and function names? Any type other than primitive/built in ones are usually camel case so lower case keywords are more likely to clash with single word variable and function names, unless you restrict the cases of those too or allow keyword overriding or something.

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

                                  Yeah, it's in my edit I realized the same thing. I'm thinking it doesn't actually really make sense and the real reason is more "the specific way C does it causes a lot of problems so we're not poking syntax like that with a 10 foot pole" + "it makes writing the parser easier" + maybe a bit of "it makes grepping easier"

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

                                    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.

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

                                    Yeah, I mean Rust is only verbose if you want it to be. let foo = "bar"; is valid rust too, no need to declare the type and definitely no need to declare the lifetime.

                                    For that matter, if you ever declare something as explicitly 'static in code that isn't embedded or super optimized, you're probably doing it wrong.

                                    1 Reply Last reply
                                    0
                                    • V [email protected]

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

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

                                      ok but then you can't do Rust, so this does not apply.

                                      but if you did.. !

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

                                        ok but then you can't do Rust, so this does not apply.

                                        but if you did.. !

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

                                        Probably would still use TypeScript, because I use that for work. 🤷‍♂️ Rust just seems like... a lot. Regarding Rust, I've seen a lot of praises and a not so insignificant amount of complaints that make me very hesitant to take the plunge. Can't remember off the top of my head what it was, specifically, but it was enough for me to write it off, that much I remember.

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

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

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

                                          STRING A WHAT, MOTHERFUCKER

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