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. Ever use this syntax in C# 7?

Ever use this syntax in C# 7?

Scheduled Pinned Locked Moved The Lounge
csharppythonrubycsscom
20 Posts 15 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.
  • Richard DeemingR Richard Deeming

    OriginalGriff wrote:

    Can't see how this makes maintenance easier at all...

    You can probably find people making the same argument for every feature ever introduced since v1.0! :-D I assume you don't use anonymous methods[^] either? Because manually writing a private class to represent a closure makes maintenance so much easier. :laugh: In this specific instance, they should have given the local function a more meaningful name than "_". But ignoring that, there's no real benefit to sticking with the previous version[^], which had a private static "Impl" method that was only called from the main method.


    "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

    M Offline
    M Offline
    Mladen Jankovic
    wrote on last edited by
    #11

    Richard Deeming wrote:

    class

    Classes? Are you insane? These little buggers are nightmare for maintenance. You don't need anything more than assembler, you're just trying to be hip.

    1 Reply Last reply
    0
    • R R Giskard Reventlov

      I use what I need to get the job done - if it is that syntax and is readable and easy to maintain...

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

      It's becoming like every other ms product: 90% of the features must be [at best] barely useful. (feeling kind today - avoiding negatives.)

      Signature not found error error: Unable to throw signature not found error.

      1 Reply Last reply
      0
      • OriginalGriffO OriginalGriff

        The more they add to the language, the more I look at it and think it's time to rip it apart and create D# or whatever. Some of this seems to have been added to please one person who might use it, instead of being a general solution to a widespread problem. Can't see how this makes maintenance easier at all...

        Bad command or file name. Bad, bad command! Sit! Stay! Staaaay... AntiTwitter: @DalekDave is now a follower!

        W Offline
        W Offline
        W Balboos GHB
        wrote on last edited by
        #13

        With people, we note them as "Jackass of all trades - Master of None". Where's my damn QuickC ?

        Ravings en masse^

        "The difference between genius and stupidity is that genius has its limits." - Albert Einstein

        "If you are searching for perfection in others, then you seek disappointment. If you are seek perfection in yourself, then you will find failure." - Balboos HaGadol Mar 2010

        1 Reply Last reply
        0
        • M Marc Clifton

          return _(); IEnumerable _() {...}

          Found this on [MoreLinq](https://github.com/morelinq/MoreLINQ/blob/master/MoreLinq/DistinctBy.cs), it actually took an [SO](https://stackoverflow.com/questions/45911116/meaning-of-the-syntax-return-ienumerabletsource) lookup for me to realize they were use a local method with an "anonymous" name. > In this context, the underscore is just an arbitrary name for a local function (which is a new feature introduced in C# 7.0). If you prefer, you could replace the underscore by a more descriptive name. :^) C# is starting to look more like Ruby/Python. The explanation is useful though: > By the way, the reason for having two methods here is so that, in case any argument is null, ArgumentNullException will be thrown immediately when DistinctBy is called instead of when the result is enumerated (due to the presence of the yield return statement). Though, putting this on the same line...I agree with what others wrote. X|

          Latest Article - Class-less Coding - Minimalist C# and Why F# and Function Programming Has Some Advantages Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny Artificial intelligence is the only remedy for natural stupidity. - CDP1802

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

          Never used it exactly like this, no. But I've used it when using a lambda to satisfy a delegate/action/func parameter with at least one parameter of its own where I literally do not care about the lambda parameter. Ex. _ => { /*....*/ }

          1 Reply Last reply
          0
          • D Dave Kreskowiak

            I can see the value in local functions but, I agree, that code could have been written for better readability. Another one that doesn't quite sit well with me is the new Expression-bodied Members[^] and Throw Expressions. That just makes the code harder to understand if you're new to C#. This one depends more on understanding the convention being used instead of on the intent of the code.

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

            Lambdas have become so important for the language that I don't see the issue with expression-bodied members. It's pretty easy to figure out what they mean even if you've never seen them before. But I can see the argument for "it wasn't needed so why add it?" The throw expressions with a null-coalescing operator, however, is a very logical addition in my opinion. It just makes sense. That operator is great for two things: defaults on null and errors on null. Until now you couldn't do the second instead having to fall back on if(X == null) throw /*error*/. Granted that isn't much boilerplate compared to the handler code that was simplified with ?., but it just makes sense that ?? should make it unnecessary.

            D 1 Reply Last reply
            0
            • J Jon McKee

              Lambdas have become so important for the language that I don't see the issue with expression-bodied members. It's pretty easy to figure out what they mean even if you've never seen them before. But I can see the argument for "it wasn't needed so why add it?" The throw expressions with a null-coalescing operator, however, is a very logical addition in my opinion. It just makes sense. That operator is great for two things: defaults on null and errors on null. Until now you couldn't do the second instead having to fall back on if(X == null) throw /*error*/. Granted that isn't much boilerplate compared to the handler code that was simplified with ?., but it just makes sense that ?? should make it unnecessary.

              D Offline
              D Offline
              Dave Kreskowiak
              wrote on last edited by
              #16

              Oh, I can see the value in it, but like I said, someone new to this looks at that and goes "what the :elephant: is THAT?!". I know this because I had three people who have some curly language experience come up, see this, and said that very thing.

              System.ItDidntWorkException: Something didn't work as expected. A guide to posting questions on CodeProject

              Click this: Asking questions is a skill. Seriously, do it.
              Dave Kreskowiak

              1 Reply Last reply
              0
              • S Slacker007

                I think the reason is so that there is less code on the page. Do more with less. Eventually in C# v45.6 we will be able to accomplish an entire line of code in the span of one character - a super character of sorts. Here is a sample of what a simple "Hello World" console app might look like with C# v45.6.

                a

                F Offline
                F Offline
                Forogar
                wrote on last edited by
                #17

                Don't you mean:

                public void a

                - I would love to change the world, but they won’t give me the source code.

                S 1 Reply Last reply
                0
                • F Forogar

                  Don't you mean:

                  public void a

                  - I would love to change the world, but they won’t give me the source code.

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

                  I think you missed the point of my joke. Either that, or just wasn't funny to begin with, which is totally possible. No worries. :sigh:

                  1 Reply Last reply
                  0
                  • M Marc Clifton

                    return _(); IEnumerable _() {...}

                    Found this on [MoreLinq](https://github.com/morelinq/MoreLINQ/blob/master/MoreLinq/DistinctBy.cs), it actually took an [SO](https://stackoverflow.com/questions/45911116/meaning-of-the-syntax-return-ienumerabletsource) lookup for me to realize they were use a local method with an "anonymous" name. > In this context, the underscore is just an arbitrary name for a local function (which is a new feature introduced in C# 7.0). If you prefer, you could replace the underscore by a more descriptive name. :^) C# is starting to look more like Ruby/Python. The explanation is useful though: > By the way, the reason for having two methods here is so that, in case any argument is null, ArgumentNullException will be thrown immediately when DistinctBy is called instead of when the result is enumerated (due to the presence of the yield return statement). Though, putting this on the same line...I agree with what others wrote. X|

                    Latest Article - Class-less Coding - Minimalist C# and Why F# and Function Programming Has Some Advantages Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny Artificial intelligence is the only remedy for natural stupidity. - CDP1802

                    M Offline
                    M Offline
                    Munchies_Matt
                    wrote on last edited by
                    #19

                    Dont know, pretty sure there is a C# forum for this question though. :)

                    1 Reply Last reply
                    0
                    • Richard DeemingR Richard Deeming

                      OriginalGriff wrote:

                      Can't see how this makes maintenance easier at all...

                      You can probably find people making the same argument for every feature ever introduced since v1.0! :-D I assume you don't use anonymous methods[^] either? Because manually writing a private class to represent a closure makes maintenance so much easier. :laugh: In this specific instance, they should have given the local function a more meaningful name than "_". But ignoring that, there's no real benefit to sticking with the previous version[^], which had a private static "Impl" method that was only called from the main method.


                      "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

                      J Offline
                      J Offline
                      jschell
                      wrote on last edited by
                      #20

                      Richard Deeming wrote:

                      You can probably find people making the same argument for every feature ever introduced since v1.0!

                      Version 1.0 of C you mean. Or perhaps version 1.0 of Fortran/Algol/Cobol.

                      Richard Deeming wrote:

                      Because manually writing a private class to represent a closure makes maintenance so much easier

                      And easier to read also. And those one liners make debugging a snap as well.

                      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