4 ms·
Surely the solution is heredocs? You effectively define your own comment closing string at the comment opening point.
by lozenge 9y ago
Surely the solution is heredocs? You effectively define your own comment closing string at the comment opening point.
- Athas 9y agoYes, heredocs (or "here-comments", since you want them ignored, not just stored in a string variable) would likely be a solution for all but the most pedantic. The final recourse of the pedant would be to point out that no single closing string would be appropriate in all cases, and you are in principle required to read the code you want to comment out, in order to find a closing string that is not already contained within it.
- cat199 9y ago:.,+n|grep eofstr
- okdana 9y agoI use heredocs for 'commenting out' code in shell scripts a lot. For example: : <<- 'NOOP' some code here NOOP In some languages there is a very slight performance impact to doing this, however. Especially in the shell, because it actually has to juggle file descriptors whenever a heredoc or herestring is involved — even if you're directing it into a built-in like `:`. (It only costs a few-dozen microseconds though.) Also, heredocs are irritating because they usually can't deal with indentation properly. bash and zsh support the `<<-` operator which allows you to indent the closing delimiter, but only if you use tabs. Most other languages require the delimiter to be the first thing on the line, which is tedious and confusing. Python's triple-quotes seem to solve all of these problems, and they're one of the best things about Python's grammar IMO. I wish every language had that, combined with the ability to treat expressions as statements. It'd be a little ugly in C-like languages, but certainly usable: ''' my comment ''';