避免参数语义不明确 (Avoid Naked Parameters)
约 211 字小于 1 分钟
2025-09-04
函数调用中的意义不明确的参数可能会损害可读性。当参数名称的含义不明显时,请为参数添加 C 样式注释 (/* ... */)
| Bad | Good |
|---|---|
| |
对于上面的示例代码,还有一种更好的处理方式是将上面的 bool 类型换成自定义类型。将来,该参数可以支持不仅仅局限于两个状态(true/false)。
type Region int
const (
UnknownRegion Region = iota
Local
)
type Status int
const (
StatusReady Status= iota + 1
StatusDone
// Maybe we will have a StatusInProgress in the future.
)
func printInfo(name string, region Region, status Status)更新日志
2025/9/4 15:48
查看所有更新日志
a059b-新增Uber的Go语言规范于
