Go Proverbs • Go Proverbs - Rob Pike - Gopherfest - November 18, 2015 • https://www.youtube.com/watch?v=PAAkCSZUG1c • go-proverbs.github.io • https://go-proverbs.github.io
Go Proverbs • Don't communicate by sharing memory, share memory by communicating. • The bigger the interface, the weaker the abstraction. • Gofmt's style is no one's favorite, yet gofmt is everyone's favorite. • A little copying is better than a little dependency. • Clear is better than clever. • Reflection is never clear. • etc..
Constants with iota • The ninth letter of the Greek alphabet (Ι, ι) • Pronunciations; • ຊਓɿΠΦλ • ֎ਓɿōŘśŏŦ (ʌɪˈəʊtə) • Enumeration constants • Expressions can be implicitly repeated
• Table-driven tests • https://github.com/golang/go/wiki/TableDrivenTests • https://golang.org/src/regexp/all_test.go • Run tests by parallel rather than sequential • To save your time • To detect race condition Testing Techniques
regexp.Regexp • Implementation of regexp.Regexp • Safe for use by concurrent goroutines • Initialization cost performance is not good • Avoid initializing as locals in functions
regexp.Regexp.Copy • Implementation of regexp.Regexp • Safe for use by concurrent goroutines • Using a sync.Mutex to protect a cache • Causes degraded performance using the same Regexp • Copy method is available for go1.6 or later
Summaries • Keep Go Proverbs of Rob Pike in your mind to write go code. • https://go-proverbs.github.io • Understand how to handle Constants. • Parallelism Testing and Benchmarking. • Not to put regexp on your code as possible. • Use strings package instead of it. • (And) Read Release Notes • https://golang.org/doc/go1.7