Hacker News new | past | comments | ask | show | jobs | submit login

This is because golint complains if you do not write a comment above an exported function. While it does indeed seem silly when reading the code, the purpose is for the go documentation that is automatically generated from this.

See https://golang.org/pkg/net/http/#NewRequest for an example of this in action where the comment is essentially worthless, and this comes from the go std library.

Go's stance is that it is better to always have people document exports, even if some are trivial and duplicates, it is better to always enforce it so that comments are there for the exports that do benefit from a "why".

If you really hate the comments, in your own projects you can use Revive which is a drop-in replacement for golint and allows you to disable lint rules like comment annotations.

https://revive.run/




I think it's great it forces you to write a comment for an exported function but why the hell do I have to write down the function name again?!? It's literally 1 line below. Can the analyzer tool not grab the name of the function from that?

It makes these comments very frustrating and also more annoying to read because you always have duplicate text.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: