TL;DR
Dave Cheney がまとめた、Go でシンプルで保守しやすいコードを書くための 11 の心得。GopherCon Israel 2020 で発表された。
内容
次の 11 の心得からなる。
- Each package fulfils a single purpose(各パッケージは単一の目的を果たす)
- Handle errors explicitly(エラーは明示的に扱う)
- Return early rather than nesting deeply(深くネストせず早めに return する)
- Leave concurrency to the caller(並行処理は呼び出し側に任せる)
- Before you launch a goroutine, know when it will stop(ゴルーチンを起動する前に、いつ止まるかを知る)
- Avoid package level state(パッケージレベルの状態を避ける)
- Simplicity matters(シンプルさが大事)
- Write tests to lock in the behaviour of your package’s API(パッケージの API の振る舞いを固定するテストを書く)
- If you think it’s slow, first prove it with a benchmark(遅いと思ったら、まずベンチマークで示す)
- Moderation is a virtue(節度は美徳である)
- Maintainability counts(保守性は重要である)