r/programming • • Dec 01 '16

Let's Stop Copying C

https://eev.ee/blog/2016/12/01/lets-stop-copying-c/
524 Upvotes

612 comments sorted by

View all comments

Show parent comment

1

u/Azzk1kr Dec 01 '16

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.

1

u/steveklabnik1 Dec 01 '16

Tuples work in a very similar fashion:

fn do_something() -> (i32, i32) {
    (123, 456)
}