在即将于10月18~20日举行的QCon上海2018上,我们邀请到了知名的Go语言专家Dave Cheney。相信很多有意学习Go语言的朋友都看过他的博客:https://dave.cheney.net/about。
Dave Cheney
Dave是Heptio的资深工程师。Heptio位于西雅图,致力于帮助开发者高效使用Kubernetes。
Dave是开源贡献者,Go编程语言项目组成员。他经常在技术社区演讲,分享软件设计、性能和Go语言相关主题。
这次他将带来两个演讲。
一个是《The past, present, and future of Go》:
Go was introduced as a new open source language on November 10th, 2009. Go is a language for engineering teams who seek to build fast, scalable, and most importantly maintainable, software. This talk will reflect on the success Go has enjoyed over the past nine years, and give the audience an overview of the four new additions coming to Go 2.0; dependency management, error handling, error values, and generics.
另一个是《Practical Go》:
Go is a language designed for engineering teams. It's central themes are simplicity, readability, and maintainability. This talk will provide best practice real world advice for teams building projects in Go covering five areas; idiomatic code, package and api design, error handling, concurrency, and testing.
因为细节比较多,第2个演讲他将用90分钟时间分享Go最佳实践。具体大纲如下。
Identifiers
Choose identifiers for clarity, not brevity
Use a consistent declaraton style
Package Design
A good package starts with its name An identifier’s name includes its package name Prefer lower case package names and import paths
Rather than nesting deeply, return early
Make the zero value useful
Eschew package level state. No package level variables. Avoid global side effects.
Project Structure
Consider fewer, larger packages Arrange code into files by import statements. Prefer nouns for file names. Eschew elaborate package hierarchies, resist the desire to apply taxonomy
Keep package main small as small as possible
API Design
Design APIs that are hard to misuse. Design APIs for their default use case.
Prefer var args to []T parameters
Let callers define the interface they require
Prefer streaming interfaces
Use type assertions for optional behaviour
Error handling
Elminate handling by eliminating errors
Only handle an error once
Concurrency
Never start a goroutine without when it will stop. When sending or receiving on a channel, consider what happens if the other party never receives the message
Keep yourself busy while waiting for a goroutine. or, do the work yourself.
Leave concurrency to the caller
感兴趣的朋友可以点击阅读原文,了解更多演讲信息。