Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • 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
Code Project
  1. Home
  2. The Lounge
  3. When did syntax become so fussy?

When did syntax become so fussy?

Scheduled Pinned Locked Moved The Lounge
question
38 Posts 30 Posters 0 Views 1 Watching
  • 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.
  • C Chris Maunder

    Paraphrased from Microsoft's own docs in order to make it readable

    MyMethod(options => _ = provider switch
    {
    "option 1" => options.Method1(x => x.Prop),
    "option 2" => options.Method2(x => x.Prop),
    _ => throw new Exception($"Unsupported option: {option}")
    });

    Are we really helping the Art with this type of syntax? I'm trying to work out what we're saving here. Keystrokes? HDD space? Screen real estate?

    cheers Chris Maunder

    P Offline
    P Offline
    PIEBALDconsult
    wrote on last edited by
    #8

    Dennis Ritchie will haunt them.

    1 Reply Last reply
    0
    • C Chris Maunder

      Paraphrased from Microsoft's own docs in order to make it readable

      MyMethod(options => _ = provider switch
      {
      "option 1" => options.Method1(x => x.Prop),
      "option 2" => options.Method2(x => x.Prop),
      _ => throw new Exception($"Unsupported option: {option}")
      });

      Are we really helping the Art with this type of syntax? I'm trying to work out what we're saving here. Keystrokes? HDD space? Screen real estate?

      cheers Chris Maunder

      S Offline
      S Offline
      Slacker007
      wrote on last edited by
      #9

      looks like a candidate for the Strategy design pattern.

      1 Reply Last reply
      0
      • C Cp Coder

        I used to feel the same way until IntelliJ IDEA showed me how to reduce a block of code to a single line using similar obscure syntax. (much to my surprise!) The Lounge[^]

        Get me coffee and no one gets hurt!

        N Offline
        N Offline
        Nelek
        wrote on last edited by
        #10

        Cp-Coder wrote:

        Tonight I will have nightmares of vicious IDEs chasing after me to correct all my many mistakes!

        Kind of mandatory[^]

        M.D.V. ;) If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you Rating helpful answers is nice, but saying thanks can be even nicer.

        1 Reply Last reply
        0
        • C Chris Maunder

          Paraphrased from Microsoft's own docs in order to make it readable

          MyMethod(options => _ = provider switch
          {
          "option 1" => options.Method1(x => x.Prop),
          "option 2" => options.Method2(x => x.Prop),
          _ => throw new Exception($"Unsupported option: {option}")
          });

          Are we really helping the Art with this type of syntax? I'm trying to work out what we're saving here. Keystrokes? HDD space? Screen real estate?

          cheers Chris Maunder

          E Offline
          E Offline
          enhzflep
          wrote on last edited by
          #11

          We're saving people that think they know better from ever bothering with the nonsense. Whether or not they're correct is another matter.

          1 Reply Last reply
          0
          • C Chris Maunder

            Paraphrased from Microsoft's own docs in order to make it readable

            MyMethod(options => _ = provider switch
            {
            "option 1" => options.Method1(x => x.Prop),
            "option 2" => options.Method2(x => x.Prop),
            _ => throw new Exception($"Unsupported option: {option}")
            });

            Are we really helping the Art with this type of syntax? I'm trying to work out what we're saving here. Keystrokes? HDD space? Screen real estate?

            cheers Chris Maunder

            M Offline
            M Offline
            Maximilien
            wrote on last edited by
            #12

            ELI5 Anyone care to explain ? it looks like a switch.

            CI/CD = Continuous Impediment/Continuous Despair

            1 Reply Last reply
            0
            • C Chris Maunder

              Paraphrased from Microsoft's own docs in order to make it readable

              MyMethod(options => _ = provider switch
              {
              "option 1" => options.Method1(x => x.Prop),
              "option 2" => options.Method2(x => x.Prop),
              _ => throw new Exception($"Unsupported option: {option}")
              });

              Are we really helping the Art with this type of syntax? I'm trying to work out what we're saving here. Keystrokes? HDD space? Screen real estate?

              cheers Chris Maunder

              M Offline
              M Offline
              Marc Clifton
              wrote on last edited by
              #13

              Personally I find that 1000x more readable than switch/case or if/else, and also tells me if I haven't implemented the default option, so more robust code.

              Latest Articles:
              Client-Side Type-Based Publisher/Subscriber, Exploring Synchronous, "Event-ed", and Worker Thread Subscriptions

              1 Reply Last reply
              0
              • Greg UtasG Greg Utas

                Trying to save all the above, show how clever language designers can be, and burn out everyone else's brain cells trying to keep up with, and parse, all this shite.

                Robust Services Core | Software Techniques for Lemmings | Articles
                The fox knows many things, but the hedgehog knows one big thing.

                H Offline
                H Offline
                honey the codewitch
                wrote on last edited by
                #14

                Greg Utas wrote:

                all this shite.

                amen

                Real programmers use butterflies

                Greg UtasG 1 Reply Last reply
                0
                • C Chris Maunder

                  Paraphrased from Microsoft's own docs in order to make it readable

                  MyMethod(options => _ = provider switch
                  {
                  "option 1" => options.Method1(x => x.Prop),
                  "option 2" => options.Method2(x => x.Prop),
                  _ => throw new Exception($"Unsupported option: {option}")
                  });

                  Are we really helping the Art with this type of syntax? I'm trying to work out what we're saving here. Keystrokes? HDD space? Screen real estate?

                  cheers Chris Maunder

                  O Offline
                  O Offline
                  obermd
                  wrote on last edited by
                  #15

                  Terseness is the enemy of clarity. All programmers need to remember this. Programmers who use languages that encourage terseness need to be extra careful to not destroy clarity.

                  1 Reply Last reply
                  0
                  • C Chris Maunder

                    Paraphrased from Microsoft's own docs in order to make it readable

                    MyMethod(options => _ = provider switch
                    {
                    "option 1" => options.Method1(x => x.Prop),
                    "option 2" => options.Method2(x => x.Prop),
                    _ => throw new Exception($"Unsupported option: {option}")
                    });

                    Are we really helping the Art with this type of syntax? I'm trying to work out what we're saving here. Keystrokes? HDD space? Screen real estate?

                    cheers Chris Maunder

                    L Offline
                    L Offline
                    Lost User
                    wrote on last edited by
                    #16

                    It's part of the "how much can I pack into one LINQ / SQL statement" school of obfuscation.

                    It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it. ― Confucian Analects: Rules of Confucius about his food

                    1 Reply Last reply
                    0
                    • H honey the codewitch

                      Greg Utas wrote:

                      all this shite.

                      amen

                      Real programmers use butterflies

                      Greg UtasG Offline
                      Greg UtasG Offline
                      Greg Utas
                      wrote on last edited by
                      #17

                      But you understand it! :laugh:

                      Robust Services Core | Software Techniques for Lemmings | Articles
                      The fox knows many things, but the hedgehog knows one big thing.

                      <p><a href="https://github.com/GregUtas/robust-services-core/blob/master/README.md">Robust Services Core</a>
                      <em>The fox knows many things, but the hedgehog knows one big thing.</em></p>

                      1 Reply Last reply
                      0
                      • C Chris Maunder

                        Paraphrased from Microsoft's own docs in order to make it readable

                        MyMethod(options => _ = provider switch
                        {
                        "option 1" => options.Method1(x => x.Prop),
                        "option 2" => options.Method2(x => x.Prop),
                        _ => throw new Exception($"Unsupported option: {option}")
                        });

                        Are we really helping the Art with this type of syntax? I'm trying to work out what we're saving here. Keystrokes? HDD space? Screen real estate?

                        cheers Chris Maunder

                        G Offline
                        G Offline
                        Gary R Wheeler
                        wrote on last edited by
                        #18

                        Chris Maunder wrote:

                        Are we really helping the Art with this type of syntax?

                        No. There seems to be a modern prejudice against classic iteration (for, while) and conditionals (if). Somehow writing these same constructs as imperative statements is "more robust" and "less error-prone". Any construct that introduces a nested scope seems subject to this prejudice. Those imperative statements are only syntactic sugar supplied by the compiler. I have a hard time liking the new features in the last couple of major versions of C#. Most if not all of them seem to be this sort of syntactic sugar, and they don't really add new functionality. The features that make the most sense to me are those that let you omit specifying a type where the compiler can figure it out from context. That saves typing (even with IntelliSense) and time.

                        Software Zen: delete this;

                        J 1 Reply Last reply
                        0
                        • C Chris Maunder

                          Paraphrased from Microsoft's own docs in order to make it readable

                          MyMethod(options => _ = provider switch
                          {
                          "option 1" => options.Method1(x => x.Prop),
                          "option 2" => options.Method2(x => x.Prop),
                          _ => throw new Exception($"Unsupported option: {option}")
                          });

                          Are we really helping the Art with this type of syntax? I'm trying to work out what we're saving here. Keystrokes? HDD space? Screen real estate?

                          cheers Chris Maunder

                          P Offline
                          P Offline
                          pmauriks
                          wrote on last edited by
                          #19

                          Since vendors wanted to lock you in to their development environment rather than using the competition. Most people rely on autocomplete and suggestions for their coding. If you would prefer to use vim or another editor that doesn't do that - it makes it just that little bit harder. . . and once you are hooked, much less easy to move away . . . I may be paranoid - but it doesn't make me wrong.

                          1 Reply Last reply
                          0
                          • C Chris Maunder

                            Paraphrased from Microsoft's own docs in order to make it readable

                            MyMethod(options => _ = provider switch
                            {
                            "option 1" => options.Method1(x => x.Prop),
                            "option 2" => options.Method2(x => x.Prop),
                            _ => throw new Exception($"Unsupported option: {option}")
                            });

                            Are we really helping the Art with this type of syntax? I'm trying to work out what we're saving here. Keystrokes? HDD space? Screen real estate?

                            cheers Chris Maunder

                            M Offline
                            M Offline
                            Member 9167057
                            wrote on last edited by
                            #20

                            This particular way of typing things doesn't make terribly much sense, but it demonstrates how you can save syntax. The one method it demonstrates is a lambda, the other (and I think that's the point here) is a Switch expression. I know I miss the latter in my C++ project.

                            1 Reply Last reply
                            0
                            • J Jon McKee

                              Maybe I'm the odd one out but I don't see the issue. It's an expression syntax instead of a statement syntax. Not to mention this syntax forces an expression as the body of a case section so if your intent is to return something then that is enforced, whereas the statement syntax doesn't care. I feel like it's the same difference and motivations between the ternary operator ?: and if-else. Expression vs statement. Something simple that yields a value vs something possibly complex that may or may not. Also you save space. 6 lines vs 15 lines ;P

                              string x = "test";

                              int y = x switch {
                              "test" => 0,
                              "test1" => 1,
                              "test2" => 2,
                              _ => 3
                              };

                              int z = -1;
                              switch (x) {
                              case "test":
                              z = 0;
                              break;
                              case "test1":
                              z = 1;
                              break;
                              case "test2":
                              z = 2;
                              break;
                              default:
                              z = 3;
                              break;
                              };

                              W Offline
                              W Offline
                              Wizard of Sleeves
                              wrote on last edited by
                              #21

                              Jon McKee wrote:

                              Also you save space. 6 lines vs 15 lines

                              If it's line count to want to save, you can write:

                              int z = -1; switch (x) { case "test": z = 0; break; case "test1": z = 1; break; case "test2": z = 2; break; default: z = 3; break; };

                              Nothing succeeds like a budgie without teeth.

                              J 1 Reply Last reply
                              0
                              • C Chris Maunder

                                Paraphrased from Microsoft's own docs in order to make it readable

                                MyMethod(options => _ = provider switch
                                {
                                "option 1" => options.Method1(x => x.Prop),
                                "option 2" => options.Method2(x => x.Prop),
                                _ => throw new Exception($"Unsupported option: {option}")
                                });

                                Are we really helping the Art with this type of syntax? I'm trying to work out what we're saving here. Keystrokes? HDD space? Screen real estate?

                                cheers Chris Maunder

                                T Offline
                                T Offline
                                The Real Paps
                                wrote on last edited by
                                #22

                                Too much syntax, kills the syntax This is just syntactic sugar, probably to make it more accessible to a new generation of programmers. But under the hood it'll still generate the same stuff we grew up with. I really don't like arguments such as: yes, "but this is shorter", or "you shouldn't use loops anymore" If you write out stuff in full, intentions become clearer. But hey, I'm just an *old* programmer...

                                1 Reply Last reply
                                0
                                • W Wizard of Sleeves

                                  Jon McKee wrote:

                                  Also you save space. 6 lines vs 15 lines

                                  If it's line count to want to save, you can write:

                                  int z = -1; switch (x) { case "test": z = 0; break; case "test1": z = 1; break; case "test2": z = 2; break; default: z = 3; break; };

                                  Nothing succeeds like a budgie without teeth.

                                  J Offline
                                  J Offline
                                  Jon McKee
                                  wrote on last edited by
                                  #23

                                  Readable line counts are what matters. Most software, including the Windows 10 source, could technically be represented on a single line (get wrecked Python nerds :cool:). Also, and I might be a pedant, but I'd say this

                                  int y = x switch { "test" => 0, "test1" => 1, "test2" => 2, _ => 3 };

                                  is way more readable than this

                                  int z = -1; switch (x) { case "test": z = 0; break; case "test1": z = 1; break; case "test2": z = 2; break; default: z = 3; break; };

                                  since it has fewer columns, reads much like an array initializer syntax which is common in modern languages, and due to the restrictions on the expression syntax the case body is a relatively constant size (a compound scope isn't allowed like with the statement syntax).

                                  W 1 Reply Last reply
                                  0
                                  • G Gary R Wheeler

                                    Chris Maunder wrote:

                                    Are we really helping the Art with this type of syntax?

                                    No. There seems to be a modern prejudice against classic iteration (for, while) and conditionals (if). Somehow writing these same constructs as imperative statements is "more robust" and "less error-prone". Any construct that introduces a nested scope seems subject to this prejudice. Those imperative statements are only syntactic sugar supplied by the compiler. I have a hard time liking the new features in the last couple of major versions of C#. Most if not all of them seem to be this sort of syntactic sugar, and they don't really add new functionality. The features that make the most sense to me are those that let you omit specifying a type where the compiler can figure it out from context. That saves typing (even with IntelliSense) and time.

                                    Software Zen: delete this;

                                    J Offline
                                    J Offline
                                    Jon McKee
                                    wrote on last edited by
                                    #24

                                    Gary R. Wheeler wrote:

                                    Those imperative statements are only syntactic sugar supplied by the compiler.

                                    I see this argument a lot, but you do know for is just syntactic sugar too, right? Same with references, same with try-with-resources, same with lambdas, same with properties, same with typedefs... I could go on for hours. Most of the features of modern languages are just sugar. The real litmus test is whether that sugar is useful to add clarity, simplify a common use-case, etc.

                                    G 1 Reply Last reply
                                    0
                                    • C Chris Maunder

                                      Paraphrased from Microsoft's own docs in order to make it readable

                                      MyMethod(options => _ = provider switch
                                      {
                                      "option 1" => options.Method1(x => x.Prop),
                                      "option 2" => options.Method2(x => x.Prop),
                                      _ => throw new Exception($"Unsupported option: {option}")
                                      });

                                      Are we really helping the Art with this type of syntax? I'm trying to work out what we're saving here. Keystrokes? HDD space? Screen real estate?

                                      cheers Chris Maunder

                                      U Offline
                                      U Offline
                                      User 13647980
                                      wrote on last edited by
                                      #25

                                      There comes a point where all these lamdas and expressions become much like Regex. It may be compact, but debugging and validating it is a nightmare. There are only three constructs we need process, decision and loop :)

                                      Carpe Diem (Seize the fish)

                                      1 Reply Last reply
                                      0
                                      • J Jon McKee

                                        Readable line counts are what matters. Most software, including the Windows 10 source, could technically be represented on a single line (get wrecked Python nerds :cool:). Also, and I might be a pedant, but I'd say this

                                        int y = x switch { "test" => 0, "test1" => 1, "test2" => 2, _ => 3 };

                                        is way more readable than this

                                        int z = -1; switch (x) { case "test": z = 0; break; case "test1": z = 1; break; case "test2": z = 2; break; default: z = 3; break; };

                                        since it has fewer columns, reads much like an array initializer syntax which is common in modern languages, and due to the restrictions on the expression syntax the case body is a relatively constant size (a compound scope isn't allowed like with the statement syntax).

                                        W Offline
                                        W Offline
                                        Wizard of Sleeves
                                        wrote on last edited by
                                        #26

                                        Jon McKee wrote:

                                        (get wrecked Python nerds :cool: )

                                        People who program in Python cannot be classified as nerds. Nerds are smart.

                                        Nothing succeeds like a budgie without teeth.

                                        1 Reply Last reply
                                        0
                                        • C Chris Maunder

                                          Paraphrased from Microsoft's own docs in order to make it readable

                                          MyMethod(options => _ = provider switch
                                          {
                                          "option 1" => options.Method1(x => x.Prop),
                                          "option 2" => options.Method2(x => x.Prop),
                                          _ => throw new Exception($"Unsupported option: {option}")
                                          });

                                          Are we really helping the Art with this type of syntax? I'm trying to work out what we're saving here. Keystrokes? HDD space? Screen real estate?

                                          cheers Chris Maunder

                                          M Offline
                                          M Offline
                                          MadGerbil
                                          wrote on last edited by
                                          #27

                                          You don't have nearly enough calls to libraries that have interfaces that reference other libraries, all using dependency injection and so on.... so that getting to the code that does the 2 + 2 is fully a dozen files deep in an outdated package that is no longer maintained.

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


                                          • Login

                                          • Don't have an account? Register

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