Gosimple is a linter for Go source that specializes in simplifying your code, written by Dominik Honnef (to more or less quote from its Github description). The sorts of simplifications that
gosimple
suggests are things like using
time.Since(t)
instead of
time.Now().Sub(t)
or replacing a loop of:
for _, iname := range thing.members() {
exlist = append(exlist, iname)
}
With the better append usage of '
exlist = append(exlist,
ni.members()...)
'.
At one level these are obvious simplifications, the kind of thing that a skilled Go programmer should be automatically writing that way in the first place without prompting. Perversely, that's exactly why I love
gosimple
.
You see, I'm not a skilled Go programmer, not in this sense. I don't write Go code every day, so all of these idioms and features of the standard library don't necessarily stay on the top of my mind to be used when I'm writing or changing code. Sometimes I write straightforward brute force code because that's the idiom I can remember right now. That's where
gosimple
comes in. Because it's a program, it unerringly remembers all of these idioms and features, even if and when I (a fallible squishy human) overlook them. It'd be better for me to write the idiomatic code in the first place, but I can't always manage that. Gosimple helps get me to idiomatic code in the end.
(It also simply brings these idioms to my attention, which makes it slightly more likely that I'll remember them the next time around.)
I'm all for automated backups to my fallible mind, so I think
gosimple
is great. As a bonus, it will also help cover changes in the standard library since I last looked at a given package in detail, which does happen sometimes.
(There's also '
gofmt -s
', which I try to remember to run over my code every so often. Dominik Honnef has additional Go tools that are worth looking at, like
staticcheck
and
unused
.)