On Wed, Jan 7, 2015 at 3:06 PM, Marcus Holmes <
mfhh...@gmail.com> wrote:
>
> But I disagree that putting commands in comments *at all* is a good idea.
> Just because other languages do it doesn't make it a good idea. It's clearly
> a hack to get around some historical problem, and we're better than that.
If it makes you feel better, think of the magic comments as pragmas.
They do, after all, have a specific syntax.
I don't really agree that it is an attempt to get around an historical
problem. We use magic comments for two purposes. One is to indicate
a special but unusual feature of a function. The comments like
//go:cgo_export_dynamic are of this form. They are not quite part of
the language, since they don't affect how the code works. But they do
need to be recognized by the compiler because they mean that the
associated function requires special treatment at link time.
It seems clear to me that it's better that this kind of directive be
present in the Go source near the symbol that it affects. In C/C++
the similar idea of symbol versioning started out as a separate input
file to the linker but was soon transmogrified into directives that
can appear in the source code (rather hideous directives that are
normally hidden by preprocessor macros). If we accept that, then we
could implement this using some sort of pragma syntax, but in the
absence of a preprocessor a magic comment syntax supports all required
features. So it boils down to a matter of taste.
The second use of magic comments is things like +build and
go:generate: directives that apply to tools used to build Go code.
These directives tend to apply to an entire file. It would be
possible to use some sort of metadata file that the appropriate tool
could examine. But it's not clear why that is better. Again, I think
it is a matter of taste.
Ian