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. C# 4.0

C# 4.0

Scheduled Pinned Locked Moved The Lounge
csharpquestiondiscussionannouncement
233 Posts 75 Posters 460 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 Jamie Nordmeyer

    So now that C# 4.0 is being talked about, I was wondering what people thought would be good additions to the language. Sorry if this is a repost, but I went through several pages, and didn't see anything, so... What I'd frankly love to see would be tuples. Rather than having to use multiple 'out' parameters, you'd just return multiple values:

    public int,int MinMax(int[] numbers)
    {
    int min, max;
    // Code to calculate min/max

    return min, max;
    }

    What do you think? What would be good for the next version?

    Kyosa Jamie Nordmeyer - Taekwondo Yi (2nd) Dan Portland, Oregon, USA

    J Offline
    J Offline
    Judah Gabriel Himango
    wrote on last edited by
    #39

    I want C# that helps me write less buggy code. This can be accomplished by integrating some Spec# features like [Pure], [Immutable], etc. I want to be able to write yield return someEnumerable;. I want a terse syntax for enumerables, now that they're everywhere with LINQ. private IEnumerable<Foo> SomeFunc(IEnumerable<Bar> input) { ... } is just too wordy.

    Tech, life, family, faith: Give me a visit. I'm currently blogging about: Feelings-Based Morality of the Secular World The apostle Paul, modernly speaking: Epistles of Paul Judah Himango

    modified on Wednesday, October 1, 2008 6:39 PM

    1 Reply Last reply
    0
    • L Lost User

      So you limit yourself - how about promising yourself not to alter it without writing it down? Saves time and space.

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

      Because it will end like most of promises you (easily) give to yourself, it will almost certainly be broken. :sigh:

      [Genetic Algorithm Library]

      L 1 Reply Last reply
      0
      • C Christian Graus

        Twice, yes. Both times the C# team argued about the complexity of introducing named optional params, and I said, I'm not asking for that. just some simple syntactic sugar ( the compiler can just generate the methods that pass the defaults through ). Like banging your head against a wall. Of course, now I am not an MVP, because I hate Vista, so I can't suggest anything anymore.

        Christian Graus No longer a Microsoft MVP, but still happy to answer your questions.

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

        Christian Graus wrote:

        now I am not an MVP, because I hate Vista

        Ultimate conspiracy?

        [Genetic Algorithm Library]

        1 Reply Last reply
        0
        • J Jamie Nordmeyer

          Sigh. As I've said above numerous times, it's not NEEDED, it'd just be nice. :) The ?? operator is not needed. But it's a great shortcut. The foreach construct isn't needed. But it's a great shortcut (you could do the same thing with a while loop, checking whether the MoveNext method of the enumerator returns false). Same with the idea of tuples. I'd rather be able to return 3 or 4 values than have to deal with the messiness of out parameters, or having to define multiple structs to handle each return combination that I might need.

          Kyosa Jamie Nordmeyer - Taekwondo Yi (2nd) Dan Portland, Oregon, USA

          S Offline
          S Offline
          Sunny Ahuwanya
          wrote on last edited by
          #42

          Actually, foreach is needed. Without foreach, you can't guarantee that the Enumerable pattern is followed. You don't expect developers to consistently follow the pattern using a for or while loop.

          Sunny Ahuwanya "The beauty of the desert is that it hides a well somewhere" -- Antoine de Saint Exupéry

          R 1 Reply Last reply
          0
          • J Jamie Nordmeyer

            So now that C# 4.0 is being talked about, I was wondering what people thought would be good additions to the language. Sorry if this is a repost, but I went through several pages, and didn't see anything, so... What I'd frankly love to see would be tuples. Rather than having to use multiple 'out' parameters, you'd just return multiple values:

            public int,int MinMax(int[] numbers)
            {
            int min, max;
            // Code to calculate min/max

            return min, max;
            }

            What do you think? What would be good for the next version?

            Kyosa Jamie Nordmeyer - Taekwondo Yi (2nd) Dan Portland, Oregon, USA

            M Offline
            M Offline
            Member 96
            wrote on last edited by
            #43

            I'd really really really like to see absolutely no changes whatsoever. Seriously.


            "It's so simple to be wise. Just think of something stupid to say and then don't say it." -Sam Levenson

            S P P 3 Replies Last reply
            0
            • M MrPlankton

              How about a function's return type being part of it's signature and not just the arugment list; so int functA(string abc); string functA(string abc); does not cause a compile error when they are in same class.

              MrPlankton

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

              Yeah, but what method should be called if I want to ignore return value? 1. int i = functA("a"); // ok int functA(string) is called 2. string s = functA("a"); // ok string functA(string) is called 3. functA("a"); // wtf?

              [Genetic Algorithm Library]

              M 1 Reply Last reply
              0
              • S Sunny Ahuwanya

                I'd like them to include a compiler switch to treat extension methods as errors. I'd also like them to place a "feature freeze" on the language. A good programming language need not be updated every three years.

                Sunny Ahuwanya "The beauty of the desert is that it hides a well somewhere" -- Antoine de Saint Exupéry

                S Offline
                S Offline
                Shog9 0
                wrote on last edited by
                #45

                Sunny Ahuwanya wrote:

                A good programming language need not be updated every three years.

                True... but we're talking about C#. :-\ </cheapshot>

                ----

                You're right. These facts that you've laid out totally contradict the wild ramblings that I pulled off the back of cornflakes packets.

                P 1 Reply Last reply
                0
                • M Mladen Jankovic

                  Because it will end like most of promises you (easily) give to yourself, it will almost certainly be broken. :sigh:

                  [Genetic Algorithm Library]

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

                  Then so be it, in this case you would simply remove the "const" if it were there, meaning that it shouldn't really have been there to start with

                  C S 2 Replies Last reply
                  0
                  • M Member 96

                    I'd really really really like to see absolutely no changes whatsoever. Seriously.


                    "It's so simple to be wise. Just think of something stupid to say and then don't say it." -Sam Levenson

                    S Offline
                    S Offline
                    Sunny Ahuwanya
                    wrote on last edited by
                    #47

                    Me too. I think they already degraded the language in C# 3 by adding extension methods and partial methods just to sell LINQ.

                    Sunny Ahuwanya "The beauty of the desert is that it hides a well somewhere" -- Antoine de Saint Exupéry

                    P 1 Reply Last reply
                    0
                    • J Jamie Nordmeyer

                      So now that C# 4.0 is being talked about, I was wondering what people thought would be good additions to the language. Sorry if this is a repost, but I went through several pages, and didn't see anything, so... What I'd frankly love to see would be tuples. Rather than having to use multiple 'out' parameters, you'd just return multiple values:

                      public int,int MinMax(int[] numbers)
                      {
                      int min, max;
                      // Code to calculate min/max

                      return min, max;
                      }

                      What do you think? What would be good for the next version?

                      Kyosa Jamie Nordmeyer - Taekwondo Yi (2nd) Dan Portland, Oregon, USA

                      S Offline
                      S Offline
                      Super Lloyd
                      wrote on last edited by
                      #48

                      well, I understand it's bothersome to define a class for each possible return type. but in this simple case, how about: public int[] MinMax(int[] numbers) { int min, max; // Code to calculate min/max return new int[] {min, max}; } BTW I don't like Power Collection, they code is convilted and my implementation of RedBlackTree is 7 times faster. OK I'll share it very soon!

                      A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station.... _________________________________________________________ My programs never have bugs, they just develop random features.

                      J 1 Reply Last reply
                      0
                      • L Lost User

                        Why const? What will it even do besides limit the programmer in the usage of said parameters?

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

                        1. one of main differences between high-level languages and assembly language is that they introduces many ways to limit the programmer 2. const keyword is not only a limitation it is also a reminder for you and for others that there is a reason why something should not be changed. And const is certainly a better solution than running around the office saying 'promise me that you will not try to change data returned by SomeLongAndCrypticFunctionName'

                        [Genetic Algorithm Library]

                        R 1 Reply Last reply
                        0
                        • C Christian Graus

                          Yes, it's something the compiler could easily do for you.

                          Christian Graus No longer a Microsoft MVP, but still happy to answer your questions.

                          D Offline
                          D Offline
                          DavidNohejl
                          wrote on last edited by
                          #50

                          Christian Graus wrote:

                          compiler could easily do

                          Nope, or at least not around '04 http://blogs.msdn.com/csharpfaq/archive/2004/03/07/85556.aspx[^]


                          [My Blog]
                          "Visual studio desperately needs some performance improvements. It is sometimes almost as slow as eclipse." - Rüdiger Klaehn
                          "Real men use mspaint for writing code and notepad for designing graphics." - Anna-Jayne Metcalfe

                          1 Reply Last reply
                          0
                          • C Christian Graus

                            I'd love to see a const keyword on parameters to methods, and optional parameters. Both of which seem simple enough.

                            Christian Graus No longer a Microsoft MVP, but still happy to answer your questions.

                            D Offline
                            D Offline
                            Daniel Grunwald
                            wrote on last edited by
                            #51

                            What kind of const? C++ const? That wouldn't be too useful in C#: most fields are references, so I would still be able to do:

                            M(const X x) {
                            x.Y.Z = 42;
                            }

                            A "deep" const would be more useful. But being "const" (in the C++ sense) just prevents M from changing the object. It can still be changed through other references inside M (by methods called by M or from other threads). I'd rather have a const that solves THAT problem - give me a "const" object in that sense, and it's automatically thread-safe! I have the impression that the C# team wants to address that last part - they've stated quite often that they want to make multi-threaded programming easier. A C++ const would be counterproductive to that.

                            1 Reply Last reply
                            0
                            • S Super Lloyd

                              well, I understand it's bothersome to define a class for each possible return type. but in this simple case, how about: public int[] MinMax(int[] numbers) { int min, max; // Code to calculate min/max return new int[] {min, max}; } BTW I don't like Power Collection, they code is convilted and my implementation of RedBlackTree is 7 times faster. OK I'll share it very soon!

                              A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station.... _________________________________________________________ My programs never have bugs, they just develop random features.

                              J Offline
                              J Offline
                              Jamie Nordmeyer
                              wrote on last edited by
                              #52

                              Elegant, indeed, and I've done this before. But it gets messy if you want to return an integer, 2 strings, and a DateTime, for example. You can create a struct to return this data, and object array (yuch), or use out parameters. Tuples just look cleaner to me. :)

                              Kyosa Jamie Nordmeyer - Taekwondo Yi (2nd) Dan Portland, Oregon, USA

                              S 1 Reply Last reply
                              0
                              • J Jamie Nordmeyer

                                Elegant, indeed, and I've done this before. But it gets messy if you want to return an integer, 2 strings, and a DateTime, for example. You can create a struct to return this data, and object array (yuch), or use out parameters. Tuples just look cleaner to me. :)

                                Kyosa Jamie Nordmeyer - Taekwondo Yi (2nd) Dan Portland, Oregon, USA

                                S Offline
                                S Offline
                                Super Lloyd
                                wrote on last edited by
                                #53

                                Yeah, it's what I mean by "it is cumbersome to create a class for all possible returns type" I guess it's syntaxic sugar but the compiler does a lot of syntaxic sugar already (foreach/yield, var, etc...) But the only clean implementation I can think of is to return a struct kind of struct FunctionMinMaxReturns { public double Min; public double Max; } And I could foresee the type explosion in the documentation if the compiler does that (because these types need to be documented for the developer's sake) An other alternative but it works only in an untyped world, is simply to return object[] from all this tuples function.

                                A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station.... _________________________________________________________ My programs never have bugs, they just develop random features.

                                1 Reply Last reply
                                0
                                • L Lost User

                                  Well, if you Don't want to alter it, why would you care to tell your compiler that? This is not C++ or C where it would have made a significant difference in some cases.

                                  C Offline
                                  C Offline
                                  Christian Graus
                                  wrote on last edited by
                                  #54

                                  Because if you're providing an interface, you provide a contract with the people who use that interface. If I write a library, I can use const to tell a user when they can trust my code not to change their stuff.

                                  Christian Graus No longer a Microsoft MVP, but still happy to answer your questions.

                                  D 1 Reply Last reply
                                  0
                                  • L Lost User

                                    Then so be it, in this case you would simply remove the "const" if it were there, meaning that it shouldn't really have been there to start with

                                    C Offline
                                    C Offline
                                    Christian Graus
                                    wrote on last edited by
                                    #55

                                    Do you never write code that other people will use ?

                                    Christian Graus No longer a Microsoft MVP, but still happy to answer your questions.

                                    1 Reply Last reply
                                    0
                                    • C Christian Graus

                                      I'd love to see a const keyword on parameters to methods, and optional parameters. Both of which seem simple enough.

                                      Christian Graus No longer a Microsoft MVP, but still happy to answer your questions.

                                      A Offline
                                      A Offline
                                      Ashley van Gerven
                                      wrote on last edited by
                                      #56

                                      BTW - am I correct in saying you can only apply const to value types? That's the behaviour I seem to get with C# 3.0

                                      "For fifty bucks I'd put my face in their soup and blow." - George Costanza

                                      1 Reply Last reply
                                      0
                                      • M Mladen Jankovic

                                        Yeah, but what method should be called if I want to ignore return value? 1. int i = functA("a"); // ok int functA(string) is called 2. string s = functA("a"); // ok string functA(string) is called 3. functA("a"); // wtf?

                                        [Genetic Algorithm Library]

                                        M Offline
                                        M Offline
                                        MrPlankton
                                        wrote on last edited by
                                        #57

                                        well then how about a void functA("a"); one would assume that this default case would be anticipated by programmer, but failing that; the syntax could be; (cast)functA("a"); and that would work to even though there is no left param; but compiler would flag functA("a"); with a warning. Would that work for you? What would you like to see?

                                        MrPlankton

                                        P 1 Reply Last reply
                                        0
                                        • S Shog9 0

                                          I was wishing for such a thing just yesterday. Ended up using an array, but the calling code is much uglier for having to unpack it. Actually, what would be great would be something like the destructuring assignment syntax recently added to JavaScript. Imagine being able to do this:

                                          double w;
                                          double h;
                                          double d;
                                          ...

                                          [w,h,d] = CalculateDimensions(...);

                                          :-D

                                          ----

                                          You're right. These facts that you've laid out totally contradict the wild ramblings that I pulled off the back of cornflakes packets.

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

                                          and return [w,h,d] ? or return {w,h,d} ?

                                          S 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