C# 4.0
-
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. 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. 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
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.
-
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.
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
-
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.
-
Free beer!
Only used beer is free. X|
-
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/maxreturn min, max;
}What do you think? What would be good for the next version?
Kyosa Jamie Nordmeyer - Taekwondo Yi (2nd) Dan Portland, Oregon, USA
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
thisendif**
string S
)
{
...
} -
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.
-
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
Unicode? RTF labels?
-
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
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.
-
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.
-
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
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.
-
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/maxreturn min, max;
}What do you think? What would be good for the next version?
Kyosa Jamie Nordmeyer - Taekwondo Yi (2nd) Dan Portland, Oregon, USA
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:
-
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.
Pawel Krakowiak wrote:
add new functionality to the existing classes
They do nothing of the sort!
-
foreach (int value in supportedValues) { if (x == value) { xIsSupported = true; break; //why keep on when you are done? :confused: } }
lol, it was late and I definately could have used a break, so I just didn't bother with the break. Or should I say didn't bother editing the post and fixing the bug when I realized I had forgotten to throw in the break. All the more reason the change would be so useful. Not only could it make for less coding, less bugs too.
-
Use a HashSet instead of an array.
I don't want to use a HashSet. The whole point of the change suggestion is flexibility to use with any type of enumerable without having to write the code to iterate through it or convert it. That and a HashSet would only be able to handle the == or != operators. What if I want to use >, <, <= or >=?
-
here here!
Kyosa Jamie Nordmeyer - Taekwondo Yi (2nd) Dan Portland, Oregon, USA
hear, hear! I had heard that proper run-time const support in the clr was far too hard or expensive, and providing a weak const keyword in c# (like c++ has got) without properly enforcing it in the clr would just be misleading. Shame though; I would have liked proper const guarantees in the clr.
-
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.
-
As for the optional parameters, they say that method overloads work better in that respect. I got used to it and don't complain. Maybe one advantage (trying to agree with MS) I can see is that when you debug your C# code the debugger (Call Stack) will show you which overload was called exactly, while it may not be apparent if a default parameter value was used...
-
Jamie Nordmeyer wrote:
C# 4.0
I haven't heard anything about it.
Jamie Nordmeyer wrote:
return min, max;
That syntax wouldn't be a good choice, because of the comma operator. I would just return an array of int. Though the only place I do that is a routine that parses a string to get a latitude and longitude (doubles in this case).
PIEBALDconsult wrote:
I would just return an array of int. Though the only place I do that is a routine that parses a string to get a latitude and longitude (doubles in this case).
I would return a System.Drawing.PointF for latitude/longitude values, or if I needed lat/long minutes and seconds, I would make a struct for it. :)
~Ribose
-
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/maxreturn min, max;
}What do you think? What would be good for the next version?
Kyosa Jamie Nordmeyer - Taekwondo Yi (2nd) Dan Portland, Oregon, USA
I'd like to see member variables treated as if they were in a class-lifetime 'using' statement. I miss the deterministic destructor from c++, but this would at least allow me to put the class in a using statement and have its member variables' dispose methods called implicitly.