Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

There have been Generic Tuples for a while in .NET... https://msdn.microsoft.com/en-us/library/system.tuple%28v=vs...


Those things suck. Every time I think about using them I always end up just using a dict or declaring a new struct.


Yeah I agree, having to keep in mind what you put into Item1, Item2, Item3 etc really isn't programmer friendly


F# uses them just fine and they don't suck. So perhaps it's just the compiler/language not dealing with them very well?

Edit: OK so it does suck that it's a reference type for even small tuples. But it's not C#/F#'s fault the CLR doesn't do a better job on those kinda things.


F# allows you to break up the tuple immediately, this tremendously aids readability as it avoids introducing confusing names.

    let (a, b) = Foo()
Compared to

    var tuple = Foo();
    var a = tuple.Item1;
    var b = tuple.Item2;
You could consider them equivalent, but conceptually it is faster to understand that a is the first result IMO.


I'm just pointing out that System.Tuple doesn't suck as the commenter was saying. It's just C#'s handling of them.


Given that the proposal specifically mentions using struct instead of class it isn't just C#'s handling that makes it difficult to leverage System.Tuple.


Funny, the BCL folks went with a class and we were assured it was a good decision. Maybe they just need to get their JIT up to date and do escape analysis so this kinda thing doesn't cost so much. (Easy for me to say they should do it...) After using Rust+LLVM I'm accustomed to the idea of not having to pay so much for features.


Which means they suck in C# doesn't it?




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: