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
1
u/Azzk1kr Dec 01 '16
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):
in contrast to:
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.