diff --git a/src/param-naked.md b/src/param-naked.md index c1b969e..357621d 100644 --- a/src/param-naked.md +++ b/src/param-naked.md @@ -1,7 +1,6 @@ # Avoid Naked Parameters -Naked parameters in function calls can hurt readability. Add C-style comments -(`/* ... */`) for parameter names when their meaning is not obvious. +Prefer using (Functional Options)[#functional-options] instead of naked parameters or split your function into a few ones:
| Bad | Good |
|---|---|
| ```go -// func printInfo(name string, isLocal, done bool) +// func getInfo(name string, useCache bool) -printInfo("foo", true, true) +getInfo("foo", true) ``` | ```go -// func printInfo(name string, isLocal, done bool) +// func getInfo(name string) -printInfo("foo", true /* isLocal */, true /* done */) +// func getInfoUsingCache(name string) + +getInfo("foo") +getInfoUsingCache("foo") ``` |
| Bad | Good |
|---|---|
| ```go -// func printInfo(name string, isLocal, done bool) +// func getInfo(name string, useCache bool) -printInfo("foo", true, true) +getInfo("foo", true) ``` | ```go -// func printInfo(name string, isLocal, done bool) +// func getInfo(name string) -printInfo("foo", true /* isLocal */, true /* done */) +// func getInfoUsingCache(name string) + +getInfo("foo") +getInfoUsingCache("foo") ``` |