- 数据要封装(尽量private)
- 参数和返回值尽量用reference(返回local variable除外)
- 能用const一定要用const
- 构造函数尽量用initializer_list进行参数初始化
临时对象是指在函数作用域或块作用域内定义的变量。
There are three easy to make mistakes in go. I present them here in the way they are often found in the wild, not in the way that is easiest to understand.
All three of these mistakes have been made in Kubernetes code, getting past code review at least once each that I know of.
What do these lines do? Make predictions and then scroll down.
func print(pi *int) { fmt.Println(*pi) }| //go:build amd64 && linux | |
| package fdsetutil | |
| import "syscall" | |
| /** | |
| // filepath: ztypes_linux_amd64.go | |
| type FdSet struct { | |
| Bits [16]int64 |
| package main | |
| import ( | |
| "fmt" | |
| "log" | |
| "net" | |
| "os" | |
| "os/signal" | |
| "syscall" | |
| ) |