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

Code comments like these frustrate me

> // constructRoutingTree constructs routing tree according to provided routes

> // gearbox implements Gearbox interface

> // New creates a new instance of gearbox

It's obvious from the names of the functions WHAT they do. The point of the comments are to tell me WHY they are necessary. The project feels like commenting for the sake of commenting. I honestly don't know why a "routing tree" is necessary and how it's helping.




> > // gearbox implements Gearbox interface

The problem I have with Go is that it does not show an object implements any interface. The implementation is implicit, i.e. you implement the method signatures, and you implement the interface. That particular comment is actually quite useful.


The java equivalent is GearBox interface with a GearBoxImpl implementation. I wrote that more times than I like.


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.


Comments above Exported functions are to appease one of the stock linters. A quick search or a experience writing Go should help you with this.


We wanted to make everything clear. We do routing using Radix tree (https://en.wikipedia.org/wiki/Radix_tree) and we call it routing tree. BTW, more documentation are on way to be added




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

Search: