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 1.1k 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.
  • S S Senthil Kumar

    Sunny Ahuwanya wrote:

    non-portable, non object oriented manner

    Hmm, that's interesting. Is it not part of the ECMA spec? Considering there's no runtime support required for extension methods, I can't see any other portability concerns. Or maybe you are considering them non-portable because the calling code won't compile without the presence of the source code containing the extension methods? And yeah, they are non object oriented if you consider static methods in a static class non-object oriented as well.

    Regards Senthil [MVP - Visual C#] _____________________________ My Home Page |My Blog | My Articles | My Flickr | WinMacro

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

    On Portability: 1) Imagine if I had to port some C# code from one framework/platform to another. Before C# 3.0, I'd had to make sure I have compatible libraries in the new framework. But now, I also have the added headache of figuring out where ALL the referenced extension methods in the code are and make sure they exist in the new framework (or write equivalent ones). It doesn't help that extension methods share the same dot notation with regular methods. I can't tell what an extension method is just by looking at the call. I'd have to write some tool that will check all referenced assemblies to point out the extension methods in the code. 2) Let's say I'm using LINQ's IEnumerable.Where extension method on a collection class someone else wrote, BUT I didn't realize the other developer had included a .Where regular method that returns an IEnumerable. My code will compile superbly without any warnings. The best part is that this code will work for months until THE CONDITION that differentiates the developer's .Where method and the LINQ's .Where method occurs. On Object Orientedness: Developer A uses List.SingleOrDefault() extensively, developer B creates a new class derived from List but would like .SingleOrDefault() to work a little differently so that all the pre-existing code will work properly with objects derived from his new class. He's stuck. :(

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

    J 1 Reply Last reply
    0
    • D ddoutel

      I don't know what I'd put in, but I know what I'd 'take out'. I'd restrict the use of the 'var' keyword to the Linq domain, only. I see major abuse coming, and I don't relish maintaining code which uses the 'var' keyword in a profligate fashion. D. T. Doutel

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

      Here here! var should only be used when you don't know the type!

      J 1 Reply Last reply
      0
      • S shiftedbitmonkey

        Can you remove the code if you have to satisfy an interface definition that contains the const keyword? ;)

        I've heard more said about less.

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

        Sure, edit the interface

        S 1 Reply 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

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

          I'd want to back up half a step.

          1 Reply Last reply
          0
          • A ASMiller

            How about the ability to partially set array values. For example, for an int array of length 10 with default values of 0..9 respectively, the following would be valid:

            myArray[3..5] = (-3, -4, -5);

            The contents would then be: 0, 1, 2, -3, -4, -5, 6, 7, 8, 9 Another idea is a composite Label (say Strings and Images). The display of CompositeLabel.Text would display a String followed by an Image then we could have things (using my mythical System.Text.SmileyFace namespace) like . . .

            myCompositeLabel.Text = "Hello, World " + System.Text.SmileyFace.BigGrin.ToImage();

            The display would then be: Hello, World :-D Anthony

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

            Reminds me of array slices in D, but that may be different.

            1 Reply Last reply
            0
            • L Lost User

              Sure, edit the interface

              S Offline
              S Offline
              shiftedbitmonkey
              wrote on last edited by
              #130

              harold aptroot wrote:

              Sure, edit the interface

              :laugh: :laugh: :laugh: And when its in a third party assembly? Are you proposing to decompile it through reflection, edit, then rebuild it to use just to omit the const? And if its obfuscated?

              I've heard more said about less.

              L 1 Reply Last reply
              0
              • A alan cooper

                I bet 99% of you disagree with this one! I would like to see multiple inheritance and full operator overloading available in C#.

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

                alan.cooper wrote:

                multiple inheritance

                Yes, or at least mixins. It's my foot and I'll blow it off if I want. :-D

                1 Reply Last reply
                0
                • S SlingBlade

                  How about a way to check against all values in an array or enumerabale at once with perhaps the keyword 'any' like below.

                  int[] supportedValues = new int[] { 3, 4, 5 }
                  int x = 4;

                  if (x == any supportedValues)
                  {
                  // Do something.
                  }

                  Instead of:

                  int[] supportedValues = new int[] { 3, 4, 5 }
                  int x = 4;
                  bool xIsSupported = false;

                  foreach (int value in supportedValues)
                  {
                  if (x == value)
                  xIsSupported = true;
                  }

                  if (xIsSupported)
                  {
                  // Do something.
                  }

                  Good idea?

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

                  Use a HashSet instead of an array.

                  S 1 Reply Last reply
                  0
                  • S S Senthil Kumar

                    Sunny Ahuwanya wrote:

                    There are so many things wrong with extension methods

                    Care to list some of them? I get that they can pollute the list of methods in a class and can cause calls to unintended methods, what else do you find wrong?

                    Regards Senthil [MVP - Visual C#] _____________________________ My Home Page |My Blog | My Articles | My Flickr | WinMacro

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

                    S. Senthil Kumar wrote:

                    I get that they can pollute the list of methods in a class and can cause calls to unintended methods

                    BINGO!! Someone finally said it. Extension methods should come with a warning label. If you search the blogosphere, you'll see developers talking about how GREAT extension methods are and how they are going to add these great "extensions" that they always wanted to the classes that came with the class library. Imagine if I'm a newbie C# programmer and I want to perform a lot of strings to base64 encoded strings. I could create a static method and call that often, I could create a new class that has an implicit string operator that will perform the conversion or I could simply extend the string class? Which do you think I'd choose?

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

                    S 1 Reply Last reply
                    0
                    • S Sunny Ahuwanya

                      S. Senthil Kumar wrote:

                      I get that they can pollute the list of methods in a class and can cause calls to unintended methods

                      BINGO!! Someone finally said it. Extension methods should come with a warning label. If you search the blogosphere, you'll see developers talking about how GREAT extension methods are and how they are going to add these great "extensions" that they always wanted to the classes that came with the class library. Imagine if I'm a newbie C# programmer and I want to perform a lot of strings to base64 encoded strings. I could create a static method and call that often, I could create a new class that has an implicit string operator that will perform the conversion or I could simply extend the string class? Which do you think I'd choose?

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

                      Sunny Ahuwanya wrote:

                      Which do you think I'd choose?

                      If you're a newbie programmer, then it doesn't matter - it'll suck. If you're just new to C#, then you'll want to play around with the tools, and it'll probably still suck. Once you've become comfortable and competent with both the language and C# in general, then you'll make a good choice given the requirements and constraints that apply. It might well be an extension method...

                      ----

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

                      S 1 Reply Last reply
                      0
                      • S Shog9 0

                        Sunny Ahuwanya wrote:

                        Which do you think I'd choose?

                        If you're a newbie programmer, then it doesn't matter - it'll suck. If you're just new to C#, then you'll want to play around with the tools, and it'll probably still suck. Once you've become comfortable and competent with both the language and C# in general, then you'll make a good choice given the requirements and constraints that apply. It might well be an extension method...

                        ----

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

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

                        Shog9 wrote:

                        If you're a newbie programmer, then it doesn't matter - it'll suck. If you're just new to C#, then you'll want to play around with the tools, and it'll probably still suck.

                        Yeah, I guess it's always good to have newbies around to laugh at! :)

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

                        1 Reply Last reply
                        0
                        • S shiftedbitmonkey

                          harold aptroot wrote:

                          Sure, edit the interface

                          :laugh: :laugh: :laugh: And when its in a third party assembly? Are you proposing to decompile it through reflection, edit, then rebuild it to use just to omit the const? And if its obfuscated?

                          I've heard more said about less.

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

                          This is the const would be a bad idea.

                          S 1 Reply Last reply
                          0
                          • H Hooga Booga

                            Free beer!

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

                            Only used beer is free. X|

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

                              And an ability to know what version is being used, to enable conditional compilation in a standard way:

                              public static string F
                              (

                              **# if VERSION>=3.5
                              this

                              endif**

                              string S
                              

                              )
                              {
                              ...
                              }

                              S 1 Reply Last reply
                              0
                              • L Lost User

                                This is the const would be a bad idea.

                                S Offline
                                S Offline
                                shiftedbitmonkey
                                wrote on last edited by
                                #139

                                I disagree. This is the reason for const. To constrain an implementation. You think its a bad idea because you can't subvert it. Hmmm... while we're at it we might as well eliminate private and protected aspects of classes as well. Get rid of readonly and just let everything be completely open. And watch the bugs fly... Do you have a solid argument against const?

                                I've heard more said about less.

                                L 1 Reply Last reply
                                0
                                • A ASMiller

                                  How about the ability to partially set array values. For example, for an int array of length 10 with default values of 0..9 respectively, the following would be valid:

                                  myArray[3..5] = (-3, -4, -5);

                                  The contents would then be: 0, 1, 2, -3, -4, -5, 6, 7, 8, 9 Another idea is a composite Label (say Strings and Images). The display of CompositeLabel.Text would display a String followed by an Image then we could have things (using my mythical System.Text.SmileyFace namespace) like . . .

                                  myCompositeLabel.Text = "Hello, World " + System.Text.SmileyFace.BigGrin.ToImage();

                                  The display would then be: Hello, World :-D Anthony

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

                                  Unicode? RTF labels?

                                  1 Reply Last reply
                                  0
                                  • S S Senthil Kumar

                                    Sunny Ahuwanya wrote:

                                    There are so many things wrong with extension methods

                                    Care to list some of them? I get that they can pollute the list of methods in a class and can cause calls to unintended methods, what else do you find wrong?

                                    Regards Senthil [MVP - Visual C#] _____________________________ My Home Page |My Blog | My Articles | My Flickr | WinMacro

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

                                    Confusion. a) People talk about them becoming members of the class, they do no such thing, they just look like it. b) Someone may ask "How do I do blah with X?" Someone else may answer "Just use X.blah()" without realizing that blah is an Extension Method (perhaps internal to the company or some third-party library that the asker doesn't have). The original asker will look in intellisense and maybe even check the documentation, but not find it. Extension Methods are user-hostile.

                                    1 Reply Last reply
                                    0
                                    • S shiftedbitmonkey

                                      I disagree. This is the reason for const. To constrain an implementation. You think its a bad idea because you can't subvert it. Hmmm... while we're at it we might as well eliminate private and protected aspects of classes as well. Get rid of readonly and just let everything be completely open. And watch the bugs fly... Do you have a solid argument against const?

                                      I've heard more said about less.

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

                                      shiftedbitmonkey wrote:

                                      Do you have a solid argument against const?

                                      Of course not, I just don't think that the reasons to include it are strong enough, so I argue ;)

                                      1 Reply Last reply
                                      0
                                      • S Sunny Ahuwanya

                                        Pawel Krakowiak wrote:

                                        I think of them as of an improvement and use them. Smile

                                        Can anyone explain to me how extension methods are an improvement? Besides helping to sell LINQ and encouraging programmers to write code in a non-portable, non object oriented manner, what is the point of extension methods?

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

                                        P Offline
                                        P Offline
                                        Pawel Krakowiak
                                        wrote on last edited by
                                        #143

                                        Sunny Ahuwanya wrote:

                                        Can anyone explain to me how extension methods are an improvement?

                                        They allow me to simply add new functionality to the existing classes, including Framework classes and I personally find them useful. I use them with Enums and String to provide some new functionality needed in a project. So their exact purpose is an improvement for me, there's nothing to add.

                                        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

                                          Y Offline
                                          Y Offline
                                          Yortw
                                          wrote on last edited by
                                          #144

                                          1. Retry keyword, from VB.NET (structured error handling) 2. Dyanmic intefaces, from VB.NET 3. AppActivate function, from VB.NET 4. Non-beta version of the parallel task library 5. Better WPF designers 6. Better user experience when working on single code file shared between .NET Framework and .NET Compact Framework projects 7. Improved keyboard/focus and dynamic control creation support in .NET Compact Framework (support for ActiveControl, ControlAdded/Removed events etc). 8. Fix for the (very rare) bug caused by compiler optimisations on the String.IsNullOrEmpty function. 9. A version of the various TryParse functions that returns the default value for expected type, instead of returning true/false with an out parameter. 10. TryParse on System.Enum. Probably a lot of other stuff too, but that's all I can think of off the top of my head :-D Tuples would also be cool :cool:

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