浏览 183
分享
Avoid Naked Parameters
Naked parameters in function calls can hurt readability. Add C-style comments(/ … /
) for parameter names when their meaning is not obvious.
Bad | Good |
---|---|
|
|
Better yet, replace naked bool
types with custom types for more readable andtype-safe code. This allows more than just two states (true/false) for thatparameter in the future.
- type Region int
- const (
- UnknownRegion Region = iota
- Local
- )
- type Status int
- const (
- StatusReady = iota + 1
- StatusDone
- // Maybe we will have a StatusInProgress in the future.
- )
- func printInfo(name string, region Region, status Status)
评论列表