 |
|
 |
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; 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
|
|
|
|
 |
|
 |
The Powers Collection or a simple hand rolled generic handles tuples, Pair<int, int>
I have always said that developers need to focus on mastering what has been provided in 2.0 before even thinking about adding more candy.
Need software developed? Offering C# development all over the United States, ERL GLOBAL, Inc is the only call you will have to make.
Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway
Most of this sig is for Google, not ego.
|
|
|
|
 |
|
 |
And I agree. Learn how to use what you have first. And I've used the Pair object before. But being able to specify a list of return values would be nice. Not necessary, no. But nice. The same thing could be said for the ?? operator though. Do you need it? No. But it's definitely nice!
Kyosa Jamie Nordmeyer - Taekwondo Yi (2nd) Dan Portland, Oregon, USA
|
|
|
|
 |
|
 |
I'd love to be able to check if say, myObject was null and if it was, return a result, and if not, return a property of myObject using the ?? operator.
Christian Graus
No longer a Microsoft MVP, but still happy to answer your questions.
|
|
|
|
 |
|
 |
Wait, that may have come out wrong but that is something I really would love to have.
Need software developed? Offering C# development all over the United States, ERL GLOBAL, Inc is the only call you will have to make.
Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway
Most of this sig is for Google, not ego.
|
|
|
|
 |
|
 |
I saw someone comment on that on another forum. Basically, you'd have something like this (using his sample syntax):
int? x = Company?.Person["Bob"]?.Age;
If Company or Company.Person["Bob"] were null, then x would be set to null, rather than getting an exception. I likes.
Kyosa Jamie Nordmeyer - Taekwondo Yi (2nd) Dan Portland, Oregon, USA
|
|
|
|
 |
|
 |
That's the best and most practical suggestion for c# I've seen. has anybody raised it to MS?
|
|
|
|
 |
|
|
 |
|
 |
Jamie Nordmeyer wrote: I saw someone comment on that on another forum.
Daniel Grunwald, TheCodeKing and myself came up with that here[^]. You're missing the final part tho, which is a ?? operator to act as the "default":
int? x = Company?.Person["Bob"]?.Age ?? null;
Of course setting null as the "default default" would also work and be handy.
“Time and space can be a bitch.” –Gushie, Quantum Leap{o,o}.oO( Check out my blog! ) |)””’) piHole.org -”-”-
|
|
|
|
 |
|
 |
Actually, the posting I saw wasn't on CodeProject. It may still have been yours, but it wasn't here. Either way, it's a fantastic idea, and I really like it!
Kyosa Jamie Nordmeyer - Taekwondo Yi (2nd) Dan Portland, Oregon, USA
|
|
|
|
 |
|
 |
Wasn't likely mine, then--that's the only place I remember discussing it; but it could have been one of the other guys. On the other hand it could have been someone else entirely, which only goes to show it must be a good idea if people are coming up with it independently! If you do find the link, let me know; it would be interesting to read what other people suggested.
It would definitely be nice to have in an upcoming version of C#.
“Time and space can be a bitch.” –Gushie, Quantum Leap{o,o}.oO( Check out my blog! ) |)””’) piHole.org -”-”-
|
|
|
|
 |
|
 |
Lol I just realized this morning as I got up how dumb that was of me last night. You didn't forget anything--null would of course be the default, that's the whole point. :P "?? null" is redundant.
“Time and space can be a bitch.” –Gushie, Quantum Leap{o,o}.oO( Check out my blog! ) |)””’) piHole.org -”-”-
|
|
|
|
 |
|
|
 |
|
 |
There is an extension of C# available that provides some help in this area: spec#.
I haven't used it myself, but I'm a big fan of Eiffel, which has deep design-by-contract support. Spec# includes notation to indicate that a variable or parameter can never be null.
BTW, if you're really interested in further reading on features for C#, the Eiffel language is a good place to start, as a language that has true generics since inception as well as tuples, anchored types, parameter covariance and many other interesting goodies.
|
|
|
|
 |
|
 |
Actually, I think the whole problem would be better solved by lifting the . operator in the same way they did for some of the other operators to handle nullable types. It is essentially making nullability a true first-class language citizen, whereby accessing a property or calling a function on a null object simply returns null rather than a NullReferenceException.
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
|
|
|
|
 |
|
 |
Tuple support is certainly nice but there are other ways to handle this. Simply having some predefined Tuple<T> type classes like we have with Func<T> and Action<T> would be more than sufficient, I think.
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
|
|
|
|
 |
|
 |
Ennis Ray Lynch, Jr. wrote: I have always said that developers need to focus on mastering what has been provided in 2.0 before even thinking about adding more candy.
Would it really be hard to "master" tuples as a return paramter? I love that feature as part of LUA and Python especially over out parametes.
Spec# sounds interesting which adds support for explicit programming by contract.
Todd Smith
|
|
|
|
 |
|
 |
It is more that .NET 2.0 provide the exact construct as required to perform the action without the need for a language update. I am not saying it is hard to master but I am constantly seeing instances of persons requesting features that are already supported.
Need software developed? Offering C# development all over the United States, ERL GLOBAL, Inc is the only call you will have to make.
Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway
Most of this sig is for Google, not ego.
|
|
|
|
 |
|
 |
Todd Smith wrote: Spec# sounds interesting which adds support for explicit programming by contract.
Yea!
Kevin
|
|
|
|
 |
|
|
 |
|
 |
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.
|
|
|
|
 |
|
 |
here here!
Kyosa Jamie Nordmeyer - Taekwondo Yi (2nd) Dan Portland, Oregon, USA
|
|
|
|
 |
|
 |
I put these things to the C# team at least twice, and they appeared too stupid to understand why they were of value.
Christian Graus
No longer a Microsoft MVP, but still happy to answer your questions.
|
|
|
|
 |
|
 |
I strongly Agree! C# cut-offs from c++ were really too deep. cons keyword (both on parameters and members signatures) shoud be a MUST in any oo language. And what about the annoying lack of default in parameters? I'd like to see c# designers and gurus dealing with Office PIA... I'm sure they would have a private build of csc.exe with default parameters implementeed .... InvokeExcelStuff(theOnlyNeededParameter, null, null, null, null, null, null, null, null, null, null, null, null, null, null....)
|
|
|
|
 |
|
 |
Giampaolo Papotti wrote: And what about the annoying lack of default in parameters? I'd like to see c# designers and gurus dealing with Office PIA... I'm sure they would have a private build of csc.exe with default parameters implementeed .... InvokeExcelStuff(theOnlyNeededParameter, null, null, null, null, null, null, null, null, null, null, null, null, null, null....)
This should become simpler...stay tuned.
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
|
|
|
|
 |