查看原文
其他

10+ 条 Go 官方谚语,你知道几条?

陈煎鱼 脑子进煎鱼了 2022-12-13

大家好,我是煎鱼。

作为一个 Go 语言开发工程师,总是在入门、深入、撕提案时能够听到各种带有 Go 特色的话语,例如:少即是多(less is more),非常有趣。

今天带来了 Go 语言之父 Rob Pike 在 2015 年分享的主题《Go Proverbs[1]》,他在该主题中讲了的 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 时所积累下来的经验。你知道多少条呢?

希望今天这篇文章能够对你有所帮助,大喊说出你最喜欢的!!!

推荐阅读


参考资料

[1]

Go Proverbs: https://www.youtube.com/watch?v=PAAkCSZUG1c


关注煎鱼,获取业内第一手消息和知识 👇



你好,我是煎鱼,出版过 Go 畅销书《Go 语言编程之旅》,再到获得 GOP(Go 领域最有观点专家)荣誉,点击蓝字查看我的出书之路

日常分享高质量文章,输出 Go 面试、工作经验、架构设计,加微信拉读者交流群,和大家交流!

您可能也对以下帖子感兴趣

文章有问题?点此查看未经处理的缓存