Go Lang: Comments Are Not Directives

https://news.ycombinator.com/item?id=9522973
by Merkur • 11 years ago
279 219 11 years ago

Go 1.4 starts to use comments as directives. I think that is a realy bad path to go on the long run. You see its beginnings in following 3 examples:

# used to set a canonical import path for a package: //import "foo"

# used to generate code: //go:generate bar

# used to document the result of a example function: //Output: foo

Comments should not be directives. Comments are free form, they do not have a syntax (as demonstrated in the examples). Comments are for humans - programms should ignore them or threat them as - comments!

It is my optinion that if Go needs some kind of annotation, than there should be a new syntax for it.

I would propose that directives to the tool chain will be marked with

#TAG: DIRECTIVE

a tool would be able to register the TAG with the go build environment. If a TAG is found in the code - the tool is called to do what ever needs to be done.

Related Stories

Loading related stories...

Source preview

news.ycombinator.com