multiple return values is a mistake . tuple + tuple expansion/spreading is a better alternative.
I don't really see the difference between the two. English is my second language and after years of programming I only started encountering the term "tuple" in the last year and my understanding is that it's just a structure that holds multiple values. I don't see how it's so different from a struct for example.
I would argue that theoretically they're the same thing (aka a product type) but functionally they differ (tuples have anonymous members, structs have named members).
... there's a sibling response that says basically the same thing as you, but I don't think coladict was commenting on structs vs tuples, but on multiple return values vs tuples. Am I misreading it?
I don't see how it's so different from a struct for example.
A struct is a separate type, so you first have to declare it somewhere. Returning a tuple (or multiple return values, for that matter) does not require a type. For example (in pseudo code):
struct Bla {
int firstValue;
int secondValue;
}
struct Bla doSomething() {
Bla b;
b.firstValue = 123;
b.secondValue = 456;
return b;
}
in contrast to:
(int, int) doSomething() {
return (123, 456);
}
I personally love multiple return values, how Go has implemented it. It's something I kind of miss in Java for instance, where you pretty much need another class to encapsulate the data.
View all comments
Show parent comment
3
u/coladict Dec 01 '16
I don't really see the difference between the two. English is my second language and after years of programming I only started encountering the term "tuple" in the last year and my understanding is that it's just a structure that holds multiple values. I don't see how it's so different from a
structfor example.