Hacker News new | past | comments | ask | show | jobs | submit login

Besides the few special built-in types that are passed by reference, everything else if passed by value. (Even "reference types" are actually structs that are passed by value (http://golang.org/pkg/reflect/#SliceHeader). And not reference types in the sense they are in other languages.

For example if you pass a struct, you are passing it by value, but if you pass a pointer to that struct, you are also passing by the argument by value. Why? Because even though the pointer contains a reference to the struct as its value, the pointer itself (which is the same as any other integer datatype to the computer) is being passed by value.

If your not familiar with pointers and C and languages with reference values like C++/Java this distinction isn't going to mean much to you however.




Yeah, I wish they hadn't called them "Reference types" - I think it's confusing. They're just value types that happen to have a small value and a pointer to the bigger data.


I would agree with that sentiment. I would have called them "auto-alias types" maybe or "auto-clone types"?




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: