Reading Lint Rules & Reasoning
Ready to commit my code I ran the Go linter. A warning I got back was “gochecknoglobals” which informed me of a variable that was global. Normally I’d just fix the rule but somehow I decided to look up the rule: https://github.com/leighmcculloch/gochecknoglobals
Usually, a good lint rule has reasoning why the behaviour is bad and the effects of it. In this case it referred me to a good article: https://peter.bourgon.org/blog/2017/06/09/theory-of-modern-go.html. Just a summary of what learned/remembered:
- Function signatures should describe what the function will do. If the function contains globals we will have no idea what side-effects it will have.
- Make dependencies explicit as arguments, so that there is no need for globals.