Skip to content

Instantly share code, notes, and snippets.

@icholy
Last active December 16, 2015 12:38
Show Gist options
  • Save icholy/5435551 to your computer and use it in GitHub Desktop.
Save icholy/5435551 to your computer and use it in GitHub Desktop.
Go Tips

1. strings, slices and interfaces are reference type, so pass them by value

src: http://research.swtch.com/godata

// don't do this
func foo(s *string) { fmt.Printf("The String: %s", *s) }
// do this
func foo(s string)  { fmt.Printf("The String: %s", s)  }

A string is a struct which contains a pointer to the underlying []byte and the length. So if you pass a pointer to a string you'll have 2 pointers to dereference.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment