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 427 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.
  • N Nemanja Trifunovic

    Christian Graus wrote:

    optional parameters

    Mixing optional parameters and overloads can lead to pretty bad mess.

    Programming Blog utf8-cpp

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

    Yeah, the C# team explicitly stated they always try to make the language simple rather than powerful. Which is retarded IMO. Sure, you can make mistakes with powerful features, but that's not the point.

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

    D 1 Reply Last reply
    0
    • T Tomz_KV

      Why do you need this feature since currently object, array and many other types can be returned or passed by reference.

      TOMZ_KV

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

      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 J 2 Replies 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.

        L Offline
        L Offline
        Leslie Sanford
        wrote on last edited by
        #24

        Christian Graus wrote:

        I'd love to see a const keyword on parameters to methods

        Seems to me they could use the readonly keyword for this instead of introducing a new keyword. EDIT: :doh: const is already a keyword in C#. Shows you how rusty my C# is already... I'm not really up on compiler writing, so I'm not sure how hard this would be to implement in C#. The compiler would have to make sure that read-only properties/methods are called on readonly/const parameters. That may be nontrivial.

        C D 2 Replies Last reply
        0
        • L Lost User

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

          L Offline
          L Offline
          Leslie Sanford
          wrote on last edited by
          #25

          harold aptroot wrote:

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

          Well, that's kind of the point. You want to limit the usage of const parameters to minimize side-effects.

          L A 2 Replies Last reply
          0
          • L Leslie Sanford

            Christian Graus wrote:

            I'd love to see a const keyword on parameters to methods

            Seems to me they could use the readonly keyword for this instead of introducing a new keyword. EDIT: :doh: const is already a keyword in C#. Shows you how rusty my C# is already... I'm not really up on compiler writing, so I'm not sure how hard this would be to implement in C#. The compiler would have to make sure that read-only properties/methods are called on readonly/const parameters. That may be nontrivial.

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

            C++ does it. I don't see why C# shouldn't, either. I accept it's less trivial than optional params.

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

            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
              Miszou
              wrote on last edited by
              #27

              I'd like to see a default class property. I wrote a thin wrapper for a web service the other day, and instead of being able to access the nested object transparently, I had to add another layer of indirection. eg: private WebServiceWrapper service = new WebServiceWrapper(); // To access the aggregate web service, we have to do this: service.AggregateService.Method(); // instead of the much more elegant: service.Method();

              Sunrise Wallpaper Project | The StartPage Randomizer | The Windows Cheerleader

              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
                MrPlankton
                wrote on last edited by
                #28

                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

                J M M 3 Replies 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
                  Shog9 0
                  wrote on last edited by
                  #29

                  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.

                  J P 2 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

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

                    Yeah, I've often thought it was kind of dumb that languages didn't do this in the first place. I think the reason though is in how the parameters are wound on to the stack. I agree, though, that if they can make it work, it'd be worth it.

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

                    M 1 Reply 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
                      Miszou
                      wrote on last edited by
                      #31

                      You would have to make sure that you correctly assigned the return value in order for this to work, right? eg: int x = funcA( "blah" ) tells the compiler to use the version that returns int, but what about these calls? funcA( "blah"); object o = funcA( "test" ); They're ambiguous calls and the compiler can't help you any more. :)

                      Sunrise Wallpaper Project | The StartPage Randomizer | The Windows Cheerleader

                      M 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.

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

                        Yup. Exactly the sort of thing I was talking about. The brackets would probably be easier syntax anyway than what I recommended for the parser to figure out.

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

                        1 Reply Last reply
                        0
                        • C Christian Graus

                          In a language where most things are passed by reference, there's even more value in an interface making an explicit promise to not alter an object that it is given to work with. How does it limit the programmer ? If you want to alter an object, don't mark it const.

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

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

                          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 1 Reply Last reply
                          0
                          • L Leslie Sanford

                            harold aptroot wrote:

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

                            Well, that's kind of the point. You want to limit the usage of const parameters to minimize side-effects.

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

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

                            M 1 Reply Last reply
                            0
                            • M Miszou

                              You would have to make sure that you correctly assigned the return value in order for this to work, right? eg: int x = funcA( "blah" ) tells the compiler to use the version that returns int, but what about these calls? funcA( "blah"); object o = funcA( "test" ); They're ambiguous calls and the compiler can't help you any more. :)

                              Sunrise Wallpaper Project | The StartPage Randomizer | The Windows Cheerleader

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

                              It's been awhile since I did any c++, but I believe you would get a compile warning with Borlands old c++ compiler and then it would take it's best guess. Casting the function call would make the compiler happy. They could do the same with next version c#.

                              MrPlankton

                              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

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

                                Jamie Nordmeyer wrote:

                                I was wondering what people thought would be good additions to the language

                                Oh, I forgot to address that. 1) Pseudo-virtual constructors: I may have a class with a constructor that takes a parameter. If I derive from that class, I have to implement a constructor to call the base constructor:

                                public class X
                                {
                                public X ( string S ) { ... }

                                ... 
                                

                                }

                                public class Y : X
                                {
                                public Y ( string S ) : base ( S ) {}
                                }

                                In this example, the Y constructor does nothing but call the base constructor, I'd rather not have to write it, it's busy-work that the compiler could do. Currently, if Y doesn't have a constructor it's an error. But the compiler already knows how to add a "default constructor", why not have it add the appropriate constructor(s) in cases like these as well? This would be most handy when defining a hierarchy of Exceptions. 2) Allow enum as a generic type constraint: public class X where T : **enum** { ... } There are operations one can perform on enum values which are rather difficult without allowing enum as a constraint.

                                1 Reply Last reply
                                0
                                • J Jamie Nordmeyer

                                  Yeah, I've often thought it was kind of dumb that languages didn't do this in the first place. I think the reason though is in how the parameters are wound on to the stack. I agree, though, that if they can make it work, it'd be worth it.

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

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

                                  You use to be able to do this in c++.

                                  MrPlankton

                                  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
                                    Sunny Ahuwanya
                                    wrote on last edited by
                                    #38

                                    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 P 2 Replies 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

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