Hacker News new | past | comments | ask | show | jobs | submit login

C# has tuples[1], but I'll agree they are not built into the language. Being able to have multiple return values from a function would be really nice rather than having to go

    return Tuple.Create(valueA, valueB);
Likewise being able to declare functions as returning multiple values in a natural fashion would be really cool.

But both of those changes are very much sugar, neither of them would make the language more powerful.

[1]http://msdn.microsoft.com/en-us/library/system.tuple.aspx




By that definition, any language that has user-defined types has tuples. Proper tuples are represented as a kind of type, not just a Tuple class.

As far as sugar - if the language is Turing complete, then every feature is syntactic sugar. You need a perverse definition of power to suggest that being able to properly handle tuples via deconstruction doesn't increase the power of the language.


> As far as sugar - if the language is Turing complete, then every feature is syntactic sugar. You need a perverse definition of power to suggest that being able to properly handle tuples via deconstruction doesn't increase the power of the language.

The difference in this case is just a couple of lines of code.

Compare that to C, where it would be a great deal more work!

(Of course a good deal of this difference is in C# using and abusing the heap so much.)

> As far as sugar - if the language is Turing complete, then every feature is syntactic sugar. You need a perverse definition of power to suggest that being able to properly handle tuples via deconstruction doesn't increase the power of the language.

Well yes, but there is the matter of how much mental effort the transformation from idealized software engineering concept to actual implementation takes the programmer.

Tuples in C# don't require that much mental effort, sure it'd be great if they were a native part of the language, but they aren't unreasonably unwieldy.

That said there are certainly times I wish multivalued returns were a natural part of C#!

Of course the problem with returning multiple unnamed values is that you can easily lose semantic information. (obviously I am ignoring comments above a function) It is not too hard to indicate the meaning of a single return value from a function, but beyond that it can get a bit harder.

(Yeah I know the scripting language people don't care, but with every passing day I am more firmly in the static typing side of things, I like my fields with both names and types!)

All that said, I can only imagine how much more productive the 80s 90s would have been if C had supported multiple return values from a function. In the very least Windows programming and HRESULTs would have been a fair bit saner!

(I do find it funny that seemingly no compiler vendor ever extended C to add multiple return values into it!)




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

Search: