Go Proverbs

The Go Proverbs are a collection of pithy sayings by Rob Pike (one of Go’s creators) that encapsulate the philosophy and best practices of the language. They were first presented at Gopherfest 2015.

The Proverbs

  1. Don’t communicate by sharing memory, share memory by communicating. Use channels to pass data between goroutines rather than locking shared variables.
  2. Concurrency is not parallelism. Concurrency is about dealing with lots of things at once. Parallelism is about doing lots of things at once.
  3. Channels orchestrate; mutexes serialize.
  4. The bigger the interface, the weaker the abstraction. Small interfaces (1-2 methods) are much more reusable and powerful.
  5. Make the zero value useful. Types should be ready to use immediately without complex initialization.
  6. interface{} says nothing. Empty interfaces provide no type safety or information.
  7. Gofmt’s style is no one’s favorite, yet gofmt is everyone’s favorite. Consistency is more important than personal preference.
  8. A little copying is better than a little dependency.
  9. Syscall must always be guarded with build tags.
  10. Cgo must always be guarded with build tags.
  11. Cgo is not Go.
  12. With the unsafe package there are no guarantees.
  13. Clear is better than clever. Readable code is superior to “clever” hacks.
  14. Reflection is never clear.
  15. Errors are values. Treat errors as data to be inspected and handled, not exceptions to be thrown.
  16. Don’t just check errors, handle them gracefully.
  17. Design the architecture, name the components, document the details.
  18. Documentation is for users.
  19. Don’t panic. Use panics only for truly unrecoverable errors.

Summary

These proverbs emphasize Go’s commitment to simplicity, readability, and safe concurrency. They serve as a guiding light for writing “idiomatic” Go code.