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.
  • 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
                • R raddevus

                  I really like that you mentioned that. Just yesterday during a live coding session another dev was showing me how to do a thing. He used a C# anonymous function / lambda expression and was trying to get it right (and this was his code) and he was typing, backspacing, typing, backspacing...waiting for intellisense, typing waiting for intellisense... I was like, "yeah, functional programming...no one can remember the syntax..." We both laughed. :rolleyes: I mean regular old OOP and structured programming is really easy to remember and type actually. *youngster waves fist and starts..."Old man...!!!" I know. :sigh:

                  J Offline
                  J Offline
                  jathalls
                  wrote on last edited by
                  #28

                  In the words of Kernighan - everyone knows that debugging is harder than coding. Therefore if you are being as clever as you can be when writing the code, you will have no chance of debugging it.

                  R J 2 Replies Last reply
                  0
                  • J Jon McKee

                    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 Offline
                    G Offline
                    Gary Wheeler
                    wrote on last edited by
                    #29

                    I suppose I could code in IL directly ... :laugh:

                    Software Zen: delete this;

                    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.

                      S Offline
                      S Offline
                      Steve Naidamast
                      wrote on last edited by
                      #30

                      Completely agree... Many of the new features to the Microsoft .NET compilers, to me, are completely unreadable. This all started with generics and LINQ years ago, when they introduced the caret as a compiler symbol. With code,they have made it ambiguous while with LINQ, they turned SQL upside down. What is the purpose of all this? To show that you can make programming as difficult as rocket science? I never use any of these features and stick with the "old ways" of writing code. It is much easier with little to ambiguity. So what if you save a few milli-seconds here or there. Who cares?

                      Steve Naidamast Sr. Software Engineer Black Falcon Software, Inc. blackfalconsoftware@outlook.com

                      1 Reply Last reply
                      0
                      • J jathalls

                        In the words of Kernighan - everyone knows that debugging is harder than coding. Therefore if you are being as clever as you can be when writing the code, you will have no chance of debugging it.

                        R Offline
                        R Offline
                        raddevus
                        wrote on last edited by
                        #31

                        jathalls wrote:

                        Therefore if you are being as clever as you can be when writing the code, you will have no chance of debugging it.

                        YES!! Nailed it!! :thumbsup::thumbsup::thumbsup:

                        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
                          Peter Adam
                          wrote on last edited by
                          #32

                          Cool kids like functional programming, so this is the new fad. Microsoft evangelists play for 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

                            J Offline
                            J Offline
                            James Lonero
                            wrote on last edited by
                            #33

                            Sad to say, C# is beginning to look more like JavaScript. The readability is lower and with more linq expressions, it takes longer to understand what the code is doing. For true engineering quality code, it should be more readable so there is less wasting of time understanding it.

                            1 Reply Last reply
                            0
                            • J jathalls

                              In the words of Kernighan - everyone knows that debugging is harder than coding. Therefore if you are being as clever as you can be when writing the code, you will have no chance of debugging it.

                              J Offline
                              J Offline
                              James Lonero
                              wrote on last edited by
                              #34

                              That is one reason I never liked to program in Unix. The Programmers wrote code that was that was terrible to understand, even for C programming. Compared to writing C for MS or PC DOS where the code was understandable. I can see why Unix has been called a "write only operating system" and why other coders who read someone else's code will call it crap.

                              J 1 Reply Last reply
                              0
                              • M Mike Hankey

                                Because doing something guilelessly makes a person appear to be much cooler.

                                The less you need, the more you have. JaxCoder.com

                                J Offline
                                J Offline
                                James Lonero
                                wrote on last edited by
                                #35

                                IMO, because doing something guilelessly makes a person appear to be a bad engineering example.

                                1 Reply Last reply
                                0
                                • J James Lonero

                                  That is one reason I never liked to program in Unix. The Programmers wrote code that was that was terrible to understand, even for C programming. Compared to writing C for MS or PC DOS where the code was understandable. I can see why Unix has been called a "write only operating system" and why other coders who read someone else's code will call it crap.

                                  J Offline
                                  J Offline
                                  jathalls
                                  wrote on last edited by
                                  #36

                                  You can't 'program in Unix', Unix is an operating system not a programming language. The point of compilers is that you can write code that will run on multiple systems. Grep can use the same 'C' code for MSDOS or UNIX or RT11.

                                  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

                                    B Offline
                                    B Offline
                                    BotReject
                                    wrote on last edited by
                                    #37

                                    I always knew it would come to this. I can see the case for using lambda functions in certain situations but I always regarded their introduction into C# as a bad move due to their potential for abuse. Sometimes adding N dimensions of abstraction is not a good move. I mean, shall we all start doing maths in base 90 just to use fewer digits? How about we join together n to the power of p math opeartors into newer short-hand operators, just to make that calculus even harder to follow? Just think - one hundred lines of calculus could be comprised into a single line!

                                    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
                                      Martin ISDN
                                      wrote on last edited by
                                      #38

                                      cryptic syntax to programmers in other languages. that's why i don't like it. i always try to write the code in a style that is familiar to all languages. when as a pascal programmer i started using c it affected my future pascal code. when i got better at javascript it affected my future c code. this monday at work they told me to use this syntax for delegates (given int add(int a, int b)):

                                      Func x;
                                      x = add;

                                      instead of:

                                      delegate int X(int a, int b);
                                      X x = add;

                                      i prefer the later, because it's more language tolerant.

                                      typedef int (*X)(int, int);
                                      X x = add;

                                      type X = function(a, b: integer) : integer;
                                      var x: X = add;

                                      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