Click here to Skip to main content

Welcome to the Lounge

   

For lazing about and discussing anything in a software developer's life that takes your fancy.
The Lounge is rated PG. If you're about to post something you wouldn't want your kid sister to read then don't post it. No flame wars, no abusive conduct and please don't post ads.

Technical discussions are welcome, but if you need specific help please use the programming forums.


 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralC# 4.0memberJamie Nordmeyer1 Oct '08 - 10:20 
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

General.Net 2.0memberEnnis Ray Lynch, Jr.1 Oct '08 - 10:22 
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.


GeneralRe: .Net 2.0memberJamie Nordmeyer1 Oct '08 - 10:25 
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! Smile | :)
 
Kyosa Jamie Nordmeyer - Taekwondo Yi (2nd) Dan
Portland, Oregon, USA

GeneralRe: .Net 2.0mvpChristian Graus1 Oct '08 - 10:38 
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.

Generalomg yesmemberEnnis Ray Lynch, Jr.1 Oct '08 - 10:40 
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.


GeneralRe: .Net 2.0memberJamie Nordmeyer1 Oct '08 - 10:42 
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

GeneralRe: .Net 2.0membermelchizidech1 Oct '08 - 23:05 
That's the best and most practical suggestion for c# I've seen. has anybody raised it to MS?
 
Smokie, this is not 'Nam. This is bowling. There are rules.
www.geticeberg.com

GeneralRe: .Net 2.0memberMember 46448822 Oct '08 - 0:30 
hm.. sexy!
GeneralRe: .Net 2.0memberchaiguy13372 Oct '08 - 18:36 
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
-”-”-

GeneralRe: .Net 2.0memberJamie Nordmeyer3 Oct '08 - 3:24 
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

GeneralRe: .Net 2.0memberchaiguy13373 Oct '08 - 3:31 
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
-”-”-

GeneralRe: .Net 2.0memberchaiguy13373 Oct '08 - 3:04 
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. D'Oh! | :doh:
 
“Time and space can be a bitch.”
–Gushie, Quantum Leap
 
{o,o}.oO(   Check out my blog!   )
|)””’)                piHole.org
-”-”-

GeneralRe: .Net 2.0memberKen_OPIS3 Oct '08 - 10:26 
no more null refs!!!!
GeneralRe: .Net 2.0membermvonballmo10 Oct '08 - 2:47 
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.
GeneralRe: .Net 2.0mvpScott Dorman6 Oct '08 - 6:19 
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

GeneralRe: .Net 2.0mvpScott Dorman6 Oct '08 - 6:22 
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

GeneralRe: .Net 2.0memberTodd Smith1 Oct '08 - 10:40 
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

GeneralRe: .Net 2.0memberEnnis Ray Lynch, Jr.1 Oct '08 - 10:44 
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.


GeneralRe: .Net 2.0memberKevin McFarlane3 Oct '08 - 4:50 
Todd Smith wrote:
Spec# sounds interesting which adds support for explicit programming by contract.

 
Yea! Smile | :)
 
Kevin

GeneralRe: .Net 2.0memberOshtri Deka1 Oct '08 - 23:21 
Hallelujah!
 

GeneralRe: C# 4.0mvpChristian Graus1 Oct '08 - 10:31 
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.

GeneralRe: C# 4.0memberJamie Nordmeyer1 Oct '08 - 10:33 
here here!
 
Kyosa Jamie Nordmeyer - Taekwondo Yi (2nd) Dan
Portland, Oregon, USA

GeneralRe: C# 4.0mvpChristian Graus1 Oct '08 - 10:38 
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.

GeneralRe: C# 4.0memberGiampaolo Papotti2 Oct '08 - 3:37 
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....)
GeneralRe: C# 4.0mvpScott Dorman6 Oct '08 - 6:25 
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

GeneralRe: C# 4.0memberandy_p2 Oct '08 - 11:21 
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.
GeneralRe: C# 4.0memberharold aptroot1 Oct '08 - 10:38 
Why const? What will it even do besides limit the programmer in the usage of said parameters?
GeneralRe: C# 4.0mvpChristian Graus1 Oct '08 - 10:40 
In a language where most things are passed by reference, there's even more value in an interface making an explicit promise to not alter an object that it is given to work with.
 
How does it limit the programmer ? If you want to alter an object, don't mark it const.
 
Christian Graus
 
No longer a Microsoft MVP, but still happy to answer your questions.

GeneralRe: C# 4.0memberharold aptroot1 Oct '08 - 11:35 
Well, if you Don't want to alter it, why would you care to tell your compiler that? This is not C++ or C where it would have made a significant difference in some cases.
GeneralRe: C# 4.0mvpChristian Graus1 Oct '08 - 13:31 
Because if you're providing an interface, you provide a contract with the people who use that interface. If I write a library, I can use const to tell a user when they can trust my code not to change their stuff.
 
Christian Graus
 
No longer a Microsoft MVP, but still happy to answer your questions.

GeneralRe: C# 4.0memberDonkey Master1 Oct '08 - 22:17 
Christian Graus wrote:
I can use const to tell a user when they can trust my code not to change their stuff.

 
erm, I don't see how that would work.
I thought that const was more of a promise to yourself, or to implementors, not to users. Nothing prevents you from calling methods and setting fields, right?
 
Ok, let me start it again.
What is the const keyword supposed to do in parameters that has an effect outside the method?
 
"Computer Science is no more about computers than astronomy is about telescopes." - Edsger Dijkstra

GeneralRe: C# 4.0memberJamie Nordmeyer2 Oct '08 - 2:17 
Here's an example of what I think he's saying:
 
public void DoSomething(const Employee emp)
{
   emp.Age = 32; // This would not compile.
}
 
An object is passed by reference, so its properties are settable. You don't want to make the Age property read only, because normally, you want the consumer to be able to set it. But what if DoSomething was meant to be a final validation, and you didn't want anything in the object to change, because it could mess up state elsewhere? The const keyword would allow the developer to leave a property or field writable, but still be able to restrict when it could be written to.
 
Kyosa Jamie Nordmeyer - Taekwondo Yi (2nd) Dan
Portland, Oregon, USA

GeneralRe: C# 4.0memberDonkey Master2 Oct '08 - 5:01 
Ok, I think I get it.
So, I would be able to call methods and get properties and fields, but forbidden from setting fields and properties.
Well, there are still the methods to change the data, so I guess that optimization-wise, this doesn't help.
 
So, it's mostly syntactic sugar, a contract constraint. I'd put it in the same category as varargs, in terms of usefulness.
You say that VB.NET has this feature today? How does it work when you import a VB.NET library to another language, like C#?
 
"Computer Science is no more about computers than astronomy is about telescopes." - Edsger Dijkstra

GeneralRe: C# 4.0memberLeslie Sanford1 Oct '08 - 11:17 
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.
GeneralRe: C# 4.0memberharold aptroot1 Oct '08 - 11:36 
So you limit yourself - how about promising yourself not to alter it without writing it down? Saves time and space.
GeneralRe: C# 4.0memberMladen Jankovic1 Oct '08 - 12:20 
Because it will end like most of promises you (easily) give to yourself, it will almost certainly be broken. Sigh | :sigh:
 

GeneralRe: C# 4.0memberharold aptroot1 Oct '08 - 12:44 
Then so be it, in this case you would simply remove the "const" if it were there, meaning that it shouldn't really have been there to start with
GeneralRe: C# 4.0mvpChristian Graus1 Oct '08 - 13:32 
Do you never write code that other people will use ?
 
Christian Graus
 
No longer a Microsoft MVP, but still happy to answer your questions.

GeneralRe: C# 4.0membershiftedbitmonkey2 Oct '08 - 8:22 
Can you remove the code if you have to satisfy an interface definition that contains the const keyword? Wink | ;)
 
I've heard more said about less.

GeneralRe: C# 4.0memberharold aptroot2 Oct '08 - 8:30 
Sure, edit the interface
GeneralRe: C# 4.0membershiftedbitmonkey2 Oct '08 - 8:35 
harold aptroot wrote:
Sure, edit the interface

 
Laugh | :laugh: Laugh | :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.

GeneralRe: C# 4.0memberharold aptroot2 Oct '08 - 9:01 
This is the const would be a bad idea.
GeneralRe: C# 4.0membershiftedbitmonkey2 Oct '08 - 9:17 
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.

GeneralRe: C# 4.0memberharold aptroot2 Oct '08 - 9:37 
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 Wink | ;)
GeneralRe: C# 4.0memberandy_p2 Oct '08 - 11:28 
Leslie Sanford wrote:
You want to limit the usage of const parameters to minimize side-effects.

 
Shouldn't it be "You want to use the limit of const parameters to minimize side-effects"? Smile | :)
GeneralRe: C# 4.0memberMladen Jankovic1 Oct '08 - 12:54 
1. one of main differences between high-level languages and assembly language is that they introduces many ways to limit the programmer
2. const keyword is not only a limitation it is also a reminder for you and for others that there is a reason why something should not be changed. And const is certainly a better solution than running around the office saying 'promise me that you will not try to change data returned by SomeLongAndCrypticFunctionName'
 

JokeRe: C# 4.0memberrastaVnuce1 Oct '08 - 20:43 
Mladen Jankovic wrote:
And const is certainly a better solution than running around the office saying 'promise me that you will not try to change data returned by SomeLongAndCrypticFunctionName'

 
Yes, but running is good for you! Laugh | :laugh:
 
To hell with circumstances; I create opportunities.

GeneralRe: C# 4.0memberIGood1 Oct '08 - 20:07 
const parameters would be very nice,
 
it's a very clear way to show me that my object has not been changed after the function to which I passed it returns
GeneralRe: C# 4.0memberDaveyM691 Oct '08 - 10:38 
Christian Graus wrote:
optional parameters

 
Ditto - one of the few things that I prefer in VB.NET. Creating loads of overloads is a royal PITA.
 
Dave
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)

GeneralRe: C# 4.0mvpChristian Graus1 Oct '08 - 10:43 
Yes, it's something the compiler could easily do for you.
 
Christian Graus
 
No longer a Microsoft MVP, but still happy to answer your questions.

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   


Advertise | Privacy | Mobile
Web04 | 2.6.130516.1 | Last Updated 19 May 2013
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid