|
I miss const more than optional parameters. I did VB .NET for a year. It has optional parameters and it put me off them really. Even though prior to this I've been a C++ dev and didn't seem to mind them then! Perhaps it was just the way they were used in VB? Or maybe I've just changed my taste?
Kevin
|
|
|
|
|
Optional parameters will probably be there. Const paramters are doubtful although it would be nice, at least as a compile-time check.
Scott Dorman Microsoft® MVP - Visual C# | MCPD
President - Tampa Bay IASA
[ Blog][ Articles][ Forum Guidelines] Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai
|
|
|
|
|
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: That syntax wouldn't be a good choice, because of the comma operator.
It'd certainly take some work on the part of the parser developers at Microsoft, but it'd still be useful in my humble opinion. What if I wanted to return an integer, 2 strings, and a DateTime? Today, I'd just use a struct or out parameters. Easy enough. It'd just be NICE to be able to return everything. Like the ?? operator. Not necessary, but still useful.
Again, just my humble opinion.
Kyosa Jamie Nordmeyer - Taekwondo Yi (2nd) Dan
Portland, Oregon, USA
|
|
|
|
|
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
|
|
|
|
|
Why do you need this feature since currently object, array and many other types can be returned or passed by reference.
TOMZ_KV
|
|
|
|
|
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
|
|
|
|
|
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
|
|
|
|
|
Surely without foreach you'd just be in the same position as Java was (pre v1.5?) where you have to make a call to getIterator() and then loop through that.
It's much more unfriendly than foreach but it still does the same thing
Russ
|
|
|
|
|
We have the anonymous type. Create an anonymous type structure in your method and return it to a var local variable.
|
|
|
|
|
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
|
|
|
|
|
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
|
|
|
|
|
You use to be able to do this in c++.
MrPlankton
|
|
|
|
|
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?
<br />
funcA( "blah");<br />
object o = funcA( "test" );<br />
They're ambiguous calls and the compiler can't help you any more.
|
|
|
|
|
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
|
|
|
|
|
MrPlankton wrote: 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
I'd rather not see it. I treat compiler warnings as errors, but from time to time I have to work with people who do stuff like try..catch with the general exception and don't even log the exception message. The compiler cries of course but no one pays attention. *sigh*
That proposed feature is very interesting, but I'm afraid of it.
|
|
|
|
|
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?
|
|
|
|
|
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
|
|
|
|
|
MrPlankton wrote: well then how about a
void functA("a");
What if there's not such method?
|
|
|
|
|
You of course would write it, to handle that case.
MrPlankton
|
|
|
|
|
MrPlankton wrote: You of course would write it, to handle that case.
I thought so. Then it's the same as with the current lack of optional method arguments - you have to write overloads and people complain. Now you would have to write void methods...
|
|
|
|
|
Well you could cast it to the method you want even if there is no left side argument.
(int)functA("stuff");
I'm just saying having the return type as part of the signiture would be nice to have from time to time.
MrPlankton
|
|
|
|
|
MrPlankton wrote: I'm just saying having the return type as part of the signiture would be nice to have from time to time
I know, I've been there myself.
|
|
|
|
|
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<mywebservice> service = new WebServiceWrapper<mywebservice>();<br />
<br />
service.AggregateService.Method();<br />
<br />
service.Method();<br />
</mywebservice></mywebservice>
|
|
|
|
|
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(...);
---- You're right.
These facts that you've laid out totally contradict the wild ramblings that I pulled off the back of cornflakes packets .
|
|
|
|