| ▲ | jtbaker 17 hours ago | |
yeah, not really an expert but my understanding is that naming the return struct automatically allocates the object and places it into the scope. I think that for the user example it works because the NewDecoder is operating on the same memory allocation in the struct. I like the idea of having named returns, since it's common to return many items as a tuple in go functions, and think it's clearer to have those named than leaving it to the user, especially if it's returning many of the same primitive type like ints/floats: ``` type IItem interface { Inventory(id int) (price float64, quantity int, err error) } ``` compared to ``` type IItem interface { Inventory(id int) (float64, int, error) } ``` but feel like the memory allocation and control flow implications make it hard to reason about at a glance for non-trivial functions. | ||