kubevirt: pkg/instancetype/instancetype.go: Avoid named returns
Is your feature request related to a problem? Please describe:
Named returns make the code harder to understand than necessary, therefore they should be avoided.
Describe the solution you’d like:
Remove named returns in pkg/instancetype/instancetype.go L814-908 and define the variables in the function bodies instead.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 25 (25 by maintainers)
As the original author I obviously agree with @iholder101 here that in this specific case there’s value in using named return variables when the implementation delegates the returns. That said the shared underlying function used by all paths does actually define these return variables within the function and should have its named return values dropped:
https://github.com/kubevirt/kubevirt/blob/ee87726a579c44609316a5d35d7dca1b7da94c87/pkg/instancetype/instancetype.go#L830-L836
I also agree with @alicefr that empty returns using named return variables should be avoided and should be documented as something to avoid.
@lyarwood Let’s move this discussion back to #11456!
@iholder101 as already mentioned in the PR, I encourage you to write this comment in the coding best-practice issue: https://github.com/kubevirt/kubevirt/issues/11259