3 ms·
Do Go comments work like syntax? Do you mean that they need to be formatted a certain way like they’re language syntax?
by steve_adams_86 6y ago
Do Go comments work like syntax? Do you mean that they need to be formatted a certain way like they’re language syntax?
- grey-area 6y agoThe Go authors have (ab)used comments to extend the language in experimental ways for code generation, build pragmas and recently file embedding. They’ve done this to avoid breaking the language stability guarantee, not sure if there were other reasons. I think it’s a mistake personally to create this sort of metalanguage in comments (now you have two problems!) but it’s easy to avoid using this most of the time as the uses are pretty esoteric.
- skrtskrt 6y agoFile embedding is a common enough use case (HTML templates, config files) that it really makes me cringe that it's being done with comments.
- grey-area 6y agoI just keep my templates and config in separate files. There are good reasons to keep them separate anyway (allows config without recompile for example) and for the apps I work on distribution isn’t a problem. So I haven’t really had to use comments as code in 7-8 years of go. Perhaps it’ll become more common with the embed stuff. But then I don’t use struct tags either so I guess I’d prefer Go to be even simpler.
- _ph_ 6y agoNo, Go comments are just comments. They have been used though to add meta-information to special tools. So unless you use those tools and require to add the specific meta-information, you can treat comments as plain comments. Hiding certain meta-information, like exporting a function with a C-compatible signature when building a shared library is not a great way of doing things, but on the other side, it is a special usage which isn't part of the language itself, so not part of its syntax.