News for hackers. Stuff that matters.
Re:Go 1.1 is released by voidlogic on Monday May 13, 2013 @08:56PM (#5702442)
There are no reference types in Go, everything in Go is passed by value.

When you pass a slice, for example, you are passing a structure that has a pointer to the underlying data by value; you could think of it as a reference BUT its not what you think it is. What you are passing around is actually a struct that is passed by value:

  type SliceHeader struct { //[1]
      Data uintptr
      Len  int
      Cap  int
   }
1: http://golang.org/pkg/reflect/#SliceHeader
Re:Go 1.1 is released by coldtea on Monday May 13, 2013 @09:49PM (#5702618)
>There are no reference types in Go, everything in Go is passed by value.

Yes, but this value is not the ACTUAL value (e.g the underlying storage).

When people (especially newcomers to pointers like the person that started this thread) speak of "pass by value" they refer to their data (the actual value).

So that Go passes _the structure_ by value is quite misleading, compared to the expectation of what "pass by value" means.

For practical purposes, I think they're better off to think of it as a reference.

Re:Go 1.1 is released by voidlogic on Monday May 13, 2013 @11:31PM (#5702885)
>>For practical purposes, I think they're better off to think of it as a reference.

No, they should learn to understand what is actually happening. Otherwise things, at best, do not make sense and, at worst, can lead to bugs when using functions like append(): http://play.golang.org/p/eTJXu6XMNJ

Re:Go 1.1 is released by bishop_mandible on Tuesday May 14, 2013 @12:56AM (#5703078)
> a structure that has a pointer to the underlying data by value

Isn't this the exact definition of a reference type?

Re:Go 1.1 is released by voidlogic on Tuesday May 14, 2013 @09:53AM (#5704788)
Except that if you are passed something like a slice and you modify the length, that change is not reflected to others like it would be with a reference. See my above code example.