News for hackers. Stuff that matters.
Re:Were multiple return values Go's biggest mistake? by porridgeraisin on Saturday March 15, 2025 @03:11PM (#43374551)
This is fairly standard and expected behaviour. Embedded pointers get copied only when you explicitly do a deep copy.
Re:Were multiple return values Go's biggest mistake? by MichaelMoser123 on Saturday March 15, 2025 @11:40PM (#43376808)
yes, however if you look at the function definition then you can't tell if the caller is passing a slice vs an array, or an interface that is implemented on a pointer vs a struct.

The semantics of the function parameter should not depend on how the function is being called.

Re:Were multiple return values Go's biggest mistake? by porridgeraisin on Sunday March 16, 2025 @04:44AM (#43377677)
> if you look at the function definition then you can't tell if the caller is passing a slice vs an array

You certainly can. If a function is `f(x []int)` it is illegal to pass a `[3]int` to it. And vice versa, if a parameter is `[3]int` you cannot pass in an `[]int` there.

> or an interface that is implemented on a pointer vs a struct. The semantics of the function parameter should not depend on how the function is being called.

In this case, the semantics of the parameter is the semantics of the interface in question. Whether that interface is implemented by a value or implemented by a pointer inside a particular user of the function is not relevant. This is good -- the decision of using pointer or value receivers on the user's struct, of course, should rest with the user.