10- 條 Go 官方諺語,你知道幾條?

作爲一個 Go 語言開發工程師,總是在入門、深入、撕提案時能夠聽到各種帶有 Go 特色的話語,例如:少即是多(less is more),非常有趣。

今天帶來了 Go 語言之父 Rob Pike 在 2015 年分享的主題《Go Proverbs》,它在該主題中講了的 10+ 條 Go 諺語,希望大家可以用上。

核心理念是:簡單、詩意、簡潔(Simple, Poetic, Pithy)。

諺語

  1. 不要通過共享內存來通信,通過通信來共享內存(Don't communicate by sharing memory, share memory by communicating)。

  2. 併發不是並行(Concurrency is not parallelism)。

  3. 通道是協調的,互斥是串行的(Channels orchestrate; mutexes serialize)。

  4. 接口越大,抽象性越弱(The bigger the interface, the weaker the abstraction)。

  5. 讓零值變得有用(Make the zero value useful)。

  6. interface{} 什麼也沒說(interface{} says nothing)。

  7. Gofmt 的風格沒有人喜歡,但 Gofmt 卻是大家的最愛(Gofmt's style is

    no one's favorite, yet gofmt is everyone's favorite)。

  8. 複製一點總比依賴一點好(A little copying is better than a little dependency)。

  9. Syscall 必須始終用 build 標籤來保護(Syscall must always be guarded with build tags)。

  10. Cgo 必須始終用構建標籤來保護(Cgo must always be guarded with build tags)。

  11. Cgo 不是 Go(Cgo is not Go)。

  12. 使用 unsafe 包沒有任何保證(With the unsafe package there are no guarantees)。

  13. 清晰的比聰明的好(Clear is better than clever)。

  14. 反射從來不是清晰的(Reflection is never clear)。

  15. 錯誤就是價值(Errors are values)。

  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)。

總結

Rob Pike 在演講中所涉及到的這 18 條諺語,是他常年在計算機軟件領域開發和設計 Go 時所積累下來的經驗。(希望能夠對你有所幫助)

本文由 Readfog 進行 AMP 轉碼,版權歸原作者所有。
來源https://mp.weixin.qq.com/s/XTlU0G9Za_fFfbsr-v25PQ