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

GoCN

共 1446字,需浏览 3分钟

 · 2022-05-23

作为一个 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 时所积累下来的经验。(希望能够对你有所帮助)


END



-猜你想看-微软开源的支持多平台多协议的网络性能检测工具 Ethrvscode 调试技巧|程序不是写出来的?是调出来的!


想要了解Go更多内容,欢迎扫描下方👇 关注 公众号,回复关键词 [实战群]  ,就有机会进群和我们进行交流~


分享、在看与点赞,至少我要拥有一个叭~

6cde5eb763adad4229792fef6a9c13d6.webpd5de19aeda87dd44c92df1ffbafab03e.webp
浏览 41
点赞
评论
收藏
分享

手机扫一扫分享

举报
评论
图片
表情
推荐
点赞
评论
收藏
分享

手机扫一扫分享

举报