4 ms·
I like C but I would prefer Rust over Go. Go may be simple but I really hate using conventions like init(), comments working like syntax, captial letter means
by cute_boi 6y ago
I like C but I would prefer Rust over Go. Go may be simple but I really hate using conventions like init(), comments working like syntax, captial letter means published etc.
- steve_adams_86 6y agoDo 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.
- Thaxll 6y agoinit() is not a convention and it's not used that much. For comments I don't understand what you're saying. And for caps I think it's better than public / private keyword.
- fwip 6y agoCertain comments have a special meaning to some tooling. In this sense, it's not very different from Javadocs. For some examples: A comment that appears right before a type or function definition is exported as documentation by the "go doc" tool. Another one is build constraints, which appear as a comment at the top of the file, like: `// +build linux` to say "only include this file if the build target is linux." Other tools use their own comment format to recognize comments meant for them.
- corytheboyd 6y agoDoesn’t Rust have “comments working like syntax” in the form of #[derive] etc.? I’ve only read through the rust book without using it for anything (yet) and have done no work on golang, so I’m legitimately curious to hear your input, not challenging you on semantics :p Edit: Rust does not use # for comments. Sorry I just had that mixed up in my head, but thanks for the answers!
- brundolf 6y ago#[...] is an attribute, more like @foo annotations in Java, not a comment. Comments do not use # in Rust
- corytheboyd 6y ago> Comments do not use # in Rust Oof what a dumb mistake, sorry about that!
- felipellrocha 6y agoIt's ok. Other people probably had the same question!
- cesarb 6y agoThese #[...] and #![...] are not comments; they're attributes (somewhat similar to Java's @Something annotations). Comments in Rust start with // or /<star> like in C or C++. There's only the special case that "doc comments" (starting with /// or /<star><star> or //! or /<star>!) are automatically converted into #[doc="..."] or #![doc="..."] attributes. The difference is that attributes are always meaningful to the compiler (and can only be used in specific places); other than doc comments (which turn into attributes), comments never are meaningful to the compiler. (edit: HN's comment markup eats the * character, I replaced them with <star> above)