4 ms·
> If it ended up in the binary it probably wasn't a comment, in the true sense. In some languages, rather than comments being a special syntactic thing, you ju
by derefr 4y ago
> If it ended up in the binary it probably wasn't a comment, in the true sense.
In some languages, rather than comments being a special syntactic thing, you just write a string-literal expression as its own statement.
Before dead code elimination was a thing, I imagine these string-literals would end up in the binary.
- schoen 4y agoI just checked, and this method is still syntactically valid (though not recommended style) in... C Javascript (Node) Python Perl Ruby Rust The strings did end up in my Python 2.7 .pyc bytecode, though not in my C or Rust binaries. My intuition was that this would work in most of these languages, but not all. For example, I thought Rust would probably complain about a value being unused. There's no such thing in general as an expression as a complete command in shell scripting, but there is a silly way to write comments as : comment instead of the normal # comment where : is a shell builtin equivalent of the "true" program, and anything otherwise syntactically valid on the line after it will be treated as command-line arguments to that builtin.
- skykooler 4y agoTechnically multiline strings in Python are the recommended style for multiline comments (e.g. docstrings).
- deleted 4y ago[deleted]
- Kwpolska 4y agoThey are recommended for docstrings, but not for comments in general. The compiler has a special case if the first statement of a function/class/module is a string (doesn’t have to be multiline), and it puts that string in the __doc__ attribute of that function/class/module — those are docstrings, and they need to be something visible to the compiler.
- tialaramex 4y agoFor Rust the Clippy linter will warn that such a line has "No effect" by default but the compiler itself won't warn you that the literal was unused. I was surprised by that too. This is also true for other literals, such as an integer.
- deleted 4y ago[deleted]