I wish C# 3.0 had optional parameters
-
... it is like the 218283th overload I am writing, and it only grows exponentially! :( Oh, and for the down-voters - this was meant to be a joke :doh:
Interested in Machine Learning in .NET? Check the Accord.NET Framework. See also Handwriting Recognition Revisited: Kernel Support Vector Machines
-
... it is like the 218283th overload I am writing, and it only grows exponentially! :( Oh, and for the down-voters - this was meant to be a joke :doh:
Interested in Machine Learning in .NET? Check the Accord.NET Framework. See also Handwriting Recognition Revisited: Kernel Support Vector Machines
When I was coding in C++, I learned that, more often than not, default parameters prevent you from making the code as flexible without sometimes dire side effects. I won't use them in C# 4.0 simply because I think they're not useful enough to override the aforementioned side-effects.
.45 ACP - because shooting twice is just silly
-----
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001 -
... it is like the 218283th overload I am writing, and it only grows exponentially! :( Oh, and for the down-voters - this was meant to be a joke :doh:
Interested in Machine Learning in .NET? Check the Accord.NET Framework. See also Handwriting Recognition Revisited: Kernel Support Vector Machines
Check this out [^]
Artificial Intelligence is no match for Natural Stupidity. http://www.hq4thmarinescomm.com[^] My Site
-
When I was coding in C++, I learned that, more often than not, default parameters prevent you from making the code as flexible without sometimes dire side effects. I won't use them in C# 4.0 simply because I think they're not useful enough to override the aforementioned side-effects.
.45 ACP - because shooting twice is just silly
-----
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001I found them very useful in certain cases such as a bool that 9 times out of 10 is one value and instead of having to add that parameter for every invocation can only use in cases where needed. Also if refactoring and you add a bool instead of going back and changing every single call you can just change as needed. Just my two sense.
Artificial Intelligence is no match for Natural Stupidity. http://www.hq4thmarinescomm.com[^] My Site
-
... it is like the 218283th overload I am writing, and it only grows exponentially! :( Oh, and for the down-voters - this was meant to be a joke :doh:
Interested in Machine Learning in .NET? Check the Accord.NET Framework. See also Handwriting Recognition Revisited: Kernel Support Vector Machines
I'm going to throw this out to you out as a suggestion: Just upgrade to .net 4.0 if possible, you should have unit tests in place to see if anything breaks :-), if everything is OK (and you don't have any weird user-machine requirements) then upgrade. I withdrew from an interview (the only time I have ever done this) about a year and a half ago because they were using .net 2.0 and had no plans to updgrade. They said that they understood that developers always wanted to "play with new toys" I challenged this (politely of course), I'd already shipped .net 3.5 stuff and the improvements to over .net 2.0 were compelling: LINQ, performance, WCF, WPF etc, not just "toys". I also pointed out that any decent dev will want to move onto the new platorm ASAP (OK, the "P" is important) and you [presumably] want to hire decent dev. I spoke to the two devs on the interview panel, one wasn't interested in learning new stuff, the other just seemed hidebound by corporate sclerosis and managerial interference. The stupid thing was this was a "startup" but under an umbrella company (itself not huge) that insisted on .net 2.0. I think I even said the company won't remain competative in the market for more than a few years.
Sort of a cross between Lawrence of Arabia and Dilbert.[^]
-Or-A Dead ringer for Kate Winslett[^] -
When I was coding in C++, I learned that, more often than not, default parameters prevent you from making the code as flexible without sometimes dire side effects. I won't use them in C# 4.0 simply because I think they're not useful enough to override the aforementioned side-effects.
.45 ACP - because shooting twice is just silly
-----
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001I do agree with you. But I do also believe that any feature can be equally misused. Just because it can be misused doesn't mean a feature should be avoided at all costs, it just means that it should be used carefully ;P
Interested in Machine Learning in .NET? Check the Accord.NET Framework. See also Handwriting Recognition Revisited: Kernel Support Vector Machines
-
I'm going to throw this out to you out as a suggestion: Just upgrade to .net 4.0 if possible, you should have unit tests in place to see if anything breaks :-), if everything is OK (and you don't have any weird user-machine requirements) then upgrade. I withdrew from an interview (the only time I have ever done this) about a year and a half ago because they were using .net 2.0 and had no plans to updgrade. They said that they understood that developers always wanted to "play with new toys" I challenged this (politely of course), I'd already shipped .net 3.5 stuff and the improvements to over .net 2.0 were compelling: LINQ, performance, WCF, WPF etc, not just "toys". I also pointed out that any decent dev will want to move onto the new platorm ASAP (OK, the "P" is important) and you [presumably] want to hire decent dev. I spoke to the two devs on the interview panel, one wasn't interested in learning new stuff, the other just seemed hidebound by corporate sclerosis and managerial interference. The stupid thing was this was a "startup" but under an umbrella company (itself not huge) that insisted on .net 2.0. I think I even said the company won't remain competative in the market for more than a few years.
Sort of a cross between Lawrence of Arabia and Dilbert.[^]
-Or-A Dead ringer for Kate Winslett[^]Wow, seems a cool thing to say in a interview :D I do have plans to upgrade, but since this code is meant to be used by others, I just can't assume everyone will have upgraded to VS2010 already. But I do appreciate your advice!
Interested in Machine Learning in .NET? Check the Accord.NET Framework. See also Handwriting Recognition Revisited: Kernel Support Vector Machines
-
Check this out [^]
Artificial Intelligence is no match for Natural Stupidity. http://www.hq4thmarinescomm.com[^] My Site
Are you referring to __arglist ? Well, I was just ranting because I wasn't willing to clobber the code with several overloads just for the sake of user experience. Using a undocumented way to pass arguments to a function would totally blow up any expectations of user-friendness :P
Interested in Machine Learning in .NET? Check the Accord.NET Framework. See also Handwriting Recognition Revisited: Kernel Support Vector Machines
modified on Sunday, December 5, 2010 8:43 AM
-
Are you referring to __arglist ? Well, I was just ranting because I wasn't willing to clobber the code with several overloads just for the sake of user experience. Using a undocumented way to pass arguments to a function would totally blow up any expectations of user-friendness :P
Interested in Machine Learning in .NET? Check the Accord.NET Framework. See also Handwriting Recognition Revisited: Kernel Support Vector Machines
modified on Sunday, December 5, 2010 8:43 AM
Only a link...if it suits your needs use it if it doesn't sh%tcan it.
Artificial Intelligence is no match for Natural Stupidity. http://www.hq4thmarinescomm.com[^] My Site
-
Only a link...if it suits your needs use it if it doesn't sh%tcan it.
Artificial Intelligence is no match for Natural Stupidity. http://www.hq4thmarinescomm.com[^] My Site
I am grateful for the link - I wasn't aware of some of the functions mentioned there. Thanks :thumbsup:
Interested in Machine Learning in .NET? Check the Accord.NET Framework. See also Handwriting Recognition Revisited: Kernel Support Vector Machines
-
When I was coding in C++, I learned that, more often than not, default parameters prevent you from making the code as flexible without sometimes dire side effects. I won't use them in C# 4.0 simply because I think they're not useful enough to override the aforementioned side-effects.
.45 ACP - because shooting twice is just silly
-----
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001We got some code at work where the prototype was hidden away somewhere so the engineer using it followed the code for examples.
TheFunc(false);
in some places,TheFunc(true);
in others. But there was one line of test code which usedTheFunc(1)
- yes, the prototype had a void parameter. That's why another call couldn't work in test mode, you had to useTheFunc(1)
first to set test mode! :doh:Join the cool kids - Come fold with us[^]
-
I'm going to throw this out to you out as a suggestion: Just upgrade to .net 4.0 if possible, you should have unit tests in place to see if anything breaks :-), if everything is OK (and you don't have any weird user-machine requirements) then upgrade. I withdrew from an interview (the only time I have ever done this) about a year and a half ago because they were using .net 2.0 and had no plans to updgrade. They said that they understood that developers always wanted to "play with new toys" I challenged this (politely of course), I'd already shipped .net 3.5 stuff and the improvements to over .net 2.0 were compelling: LINQ, performance, WCF, WPF etc, not just "toys". I also pointed out that any decent dev will want to move onto the new platorm ASAP (OK, the "P" is important) and you [presumably] want to hire decent dev. I spoke to the two devs on the interview panel, one wasn't interested in learning new stuff, the other just seemed hidebound by corporate sclerosis and managerial interference. The stupid thing was this was a "startup" but under an umbrella company (itself not huge) that insisted on .net 2.0. I think I even said the company won't remain competative in the market for more than a few years.
Sort of a cross between Lawrence of Arabia and Dilbert.[^]
-Or-A Dead ringer for Kate Winslett[^]You don't need to upgrade to .NET 4.0 in order to use optional parameters. You only need to upgrade to C# 4.0. It's perfectly possible to use VS2010 to create a .NET 2.0 application using optional parameters, LINQ, etc.
-
You don't need to upgrade to .NET 4.0 in order to use optional parameters. You only need to upgrade to C# 4.0. It's perfectly possible to use VS2010 to create a .NET 2.0 application using optional parameters, LINQ, etc.
Daniel Grunwald wrote:
It's perfectly possible to use VS2010 to create a .NET 2.0 application using optional parameters, LINQ, etc.
How (without downgrading to VB for the optional params :-))??????????? As for the LINQ, the syntax was only added in .net 3.5, I'd be surprised whether LINQ would work in .net 2.0 world (.net 3 would make more sense). I'd also question why you'd want to do that, seems like upwind urination to me.
Sort of a cross between Lawrence of Arabia and Dilbert.[^]
-Or-A Dead ringer for Kate Winslett[^] -
Daniel Grunwald wrote:
It's perfectly possible to use VS2010 to create a .NET 2.0 application using optional parameters, LINQ, etc.
How (without downgrading to VB for the optional params :-))??????????? As for the LINQ, the syntax was only added in .net 3.5, I'd be surprised whether LINQ would work in .net 2.0 world (.net 3 would make more sense). I'd also question why you'd want to do that, seems like upwind urination to me.
Sort of a cross between Lawrence of Arabia and Dilbert.[^]
-Or-A Dead ringer for Kate Winslett[^]You're confusing the compiler and the runtime. (btw: so is the thread starter. "C# 3.5" doesn't exist, there are only "C# 2.0","C# 3.0","C# 4.0" and ".NET 2.0",".NET 3.0",".NET 3.5",".NET 4.0") When using C# 4.0 to target .NET 2.0, you can use optional parameters, extension methods, LINQ, even generic variance. Remember, LINQ is just a compiler feature that translates query expressions to method calls. If you target .NET 2.0, the Select/Where/etc. methods don't exist in the framework, but it's perfectly possible to write your own. Or just include Mono's copy of those methods in your app. This works because the file format of .NET assemblies (metadata, IL instructions, etc.) hasn't changed since .NET 2.0. The why is simple: you want to target the .NET 2.0 framework already installed on millions of machines, but still want to use the new language features.
-
Daniel Grunwald wrote:
It's perfectly possible to use VS2010 to create a .NET 2.0 application using optional parameters, LINQ, etc.
How (without downgrading to VB for the optional params :-))??????????? As for the LINQ, the syntax was only added in .net 3.5, I'd be surprised whether LINQ would work in .net 2.0 world (.net 3 would make more sense). I'd also question why you'd want to do that, seems like upwind urination to me.
Sort of a cross between Lawrence of Arabia and Dilbert.[^]
-Or-A Dead ringer for Kate Winslett[^]Keith Barrow wrote:
the syntax was only added in .net 3.5
.net doesn't have syntax; the languages does. You can target earlier frameworks with the newer language compiler.
-
... it is like the 218283th overload I am writing, and it only grows exponentially! :( Oh, and for the down-voters - this was meant to be a joke :doh:
Interested in Machine Learning in .NET? Check the Accord.NET Framework. See also Handwriting Recognition Revisited: Kernel Support Vector Machines
For one method?! :wtf: You're doing something wrong.
-
... it is like the 218283th overload I am writing, and it only grows exponentially! :( Oh, and for the down-voters - this was meant to be a joke :doh:
Interested in Machine Learning in .NET? Check the Accord.NET Framework. See also Handwriting Recognition Revisited: Kernel Support Vector Machines
If you can't use the C# 4.0 compiler (you can still target .NET 3.5 if you do!): Use a parameter class.
MyMethod(new MyMethodArguments { X = 1, Z = 3 })
A parameter class has the advantage that you can add parameters and/or change the default values without breaking binary compatibility. With optional parameters, your clients have to recompile every time you change the method declaration.
-
For one method?! :wtf: You're doing something wrong.
I was just being dramatic :-D But no, it was not just for one method. :)
Interested in Machine Learning in .NET? Check the Accord.NET Framework. See also Handwriting Recognition Revisited: Kernel Support Vector Machines
-
If you can't use the C# 4.0 compiler (you can still target .NET 3.5 if you do!): Use a parameter class.
MyMethod(new MyMethodArguments { X = 1, Z = 3 })
A parameter class has the advantage that you can add parameters and/or change the default values without breaking binary compatibility. With optional parameters, your clients have to recompile every time you change the method declaration.
Well, even if you create optional parameters in VS2010 targeting .NET 3.5, users willing to use those methods under .NET 3.5 using C# 3.0 (i.e. VS2008) will not be able to take advantage of it, because the compiler does not generate overloaded constructors in this case. But using a parameter class is nice, thanks for the idea. :)
Interested in Machine Learning in .NET? Check the Accord.NET Framework. See also Handwriting Recognition Revisited: Kernel Support Vector Machines
modified on Sunday, December 5, 2010 11:26 AM
-
You're confusing the compiler and the runtime. (btw: so is the thread starter. "C# 3.5" doesn't exist, there are only "C# 2.0","C# 3.0","C# 4.0" and ".NET 2.0",".NET 3.0",".NET 3.5",".NET 4.0") When using C# 4.0 to target .NET 2.0, you can use optional parameters, extension methods, LINQ, even generic variance. Remember, LINQ is just a compiler feature that translates query expressions to method calls. If you target .NET 2.0, the Select/Where/etc. methods don't exist in the framework, but it's perfectly possible to write your own. Or just include Mono's copy of those methods in your app. This works because the file format of .NET assemblies (metadata, IL instructions, etc.) hasn't changed since .NET 2.0. The why is simple: you want to target the .NET 2.0 framework already installed on millions of machines, but still want to use the new language features.
I've just corrected the title - I am aware of the difference, but it totally slipped away into the title - thanks for noticing it :) Anyways, even if you create optional parameters in VS2010 targeting .NET 3.5, users willing to use those methods under .NET 3.5 using C# 3.0 (i.e. VS2008) will not be able to take advantage of it. For optional parameters, the compiler does not seem to create additional overloads for you. :sigh:
Interested in Machine Learning in .NET? Check the Accord.NET Framework. See also Handwriting Recognition Revisited: Kernel Support Vector Machines