Hacker News new | ask | show | jobs
by jerf 89 days ago
Actually, in practice the rule is "The delimiter for a comment is '// '", which to be clear, is slash-slash-space. Slash-slash-(not a space) is in practice a directive. There are several basic tools in the community that work on this principle including one of the basic linters.

If it would make you happier you can imagine this is part of the spec. It wouldn't change much if it was.

1 comments

The book says "Comments begin with //." and "// +build" is a special comment. It was only replaced with "//go:build" 1.17 (2021) . So your statement incorrectly implied that this strict syntax distinction between directives and comments has always existed, what happened was people started doing this slowly over time and eventually noticed the disconnect and changed "// +build" which they could because all that stuff was implementation-defined behavior. Right now gofmt handles "// +build" "//+build" and "//go:build" by moving them to the top, adding //go:build if it doesn't exist and adding a space to "//+build", which already breaks setups that add a build comment.

Why would millions of programs becoming out of date with the spec make me happy. There is value in the language maintainers and go programmers talking about the same object. I don't disagree that '// ' is standard Go style (and more readable), but it would break all the code that uses //comments /// ////.

I DO agree that it wouldn't change much if by 'it' you mean the go language and it's tooling, a proper spec does prevent arbitrary change. But it should have been added at least 5 years ago.

"So your statement incorrectly implied that this strict syntax distinction between directives and comments has always existed,"

There was no such statement. "In practice" clearly indicates the contrary about it being "strict" and certainly encompasses the possibility that it only developed over time.