# “No comments” restrictions and stack-based languages / unused strings

Some classes of question are made more interesting by banning comments. For example:

Others, such as this code-bowling question have special treatment of comments.

Many languages define delimiters for comments, but not all. So e.g. in CJam, the convention appears to be to comment your code by pushing a string with the comment text onto the stack and then popping it:

"These instructions do such-and-such";


That also has the same trivial semantics in GolfScript, although that has an explicit comment delimiter which is typically used for commenting code:

# This is a comment in GS


Some imperative languages allow any expression to be a statement, and so a simple

"This is a string";


is permitted but has trivial semantics. (E.g. JS allows this, and actually exploits it for "use strict";).

Should these ignored strings be considered comments?

• How far are you going to label things as "these ignored strings" ? There are more than 5 ways of achieving the same result as "string"; in CJam itself, not to mention other languages might more methods. – Optimizer Jan 9 '15 at 11:50
• Also, there is a fundamental difference between a line comment and "string"; . No executable code can appear after a line comment, but that's not the case for a popped string. – Optimizer Jan 9 '15 at 11:51
• @Optimizer It's the case for a block comment though. – Martin Ender Jan 9 '15 at 11:52
• What about var thisVariableNameIsNotReallyUsedButItStillProvidesFreeSpaceToStashEntropyIn? – John Dvorak Jan 9 '15 at 12:02
• @JanDvorak, I don't understand the question. If you're stashing entropy, then isn't it a completely different scenario? – Peter Taylor Jan 9 '15 at 12:17
• The exact purpose is not that relevant - be it a padding with long words or ensuring the right distribution of vowels. Is this a comment or not? – John Dvorak Jan 9 '15 at 12:19

### Yes

If it looks like a duck...

An unqualified formal language-agnostic definition of comment is probably impossible, but the essential quality is that it's a range of characters which doesn't affect execution. Generally a comment will also be able to contain most characters and character sequences other than its delimiters. Those two properties are what motivates someone to ban them as a copout for polyglots and source layout, and they're shared by strings which are pushed to the stack and immediately popped.

The question of generalisation to all dead code has been raised in the comments. If someone wants to make a case against dead code in general, either in an answer or in a separate question, they should feel free. But I don't think that's quite the same case for a number of reasons:

• The people asking questions are more likely to be familiar with dead code (which exists in pretty much every language), whereas ignored strings are easily overlooked by people who are only familiar with a few languages.
• Popped strings are the idiomatic way of commenting code in CJam, so whether or not the language spec calls them comments it seems unreasonable to claim that they're not. And if they're comments in CJam, it seems unreasonable to claim that they're not in GolfScript.
• What about var thisVariableNameIsNotReallyUsedButItStillProvidesFreeSpaceToStashEntropyIn? - is that a comment? – John Dvorak Jan 9 '15 at 12:03
• What about "str1""str2"\;;? (push two strings, then discard them in reverse order)? – John Dvorak Jan 9 '15 at 12:05
• As said by Martin in chat too. This is a very very broad area and simply cannot be restricted like its a duck. – Optimizer Jan 9 '15 at 12:09
• @Optimizer Hey don't quote me out of context. ;) I never said it's bad that it's broad. I just wanted to check with Peter that these are the implications he intended. I actually wouldn't mind a definition that rules out any code that isn't really executed. – Martin Ender Jan 9 '15 at 12:13
• @MartinBüttner my comment says "simply cannot be restricted like its a duck" . I never said that you are denying or not. – Optimizer Jan 9 '15 at 12:14
• @Optimizer "As said by Martin in chat too." I don't see any qualification that everything after "and" is your own opinion and not mine. – Martin Ender Jan 9 '15 at 12:17
• @JanDvorak, I was only thinking in terms of the simple case mentioned in the question, but I think I would agree that if push-string pop-string is treated as a comment then push-string do-stuff-not-affecting-string pop-string should also be treated as a comment. – Peter Taylor Jan 9 '15 at 12:20
• What about {push string whose presence matters but contents don't -> do something -> pop the string}, such as to pad the stack so that certain stack operations can be reused better? Should we require the string to be empty? – John Dvorak Jan 9 '15 at 12:22
• @MartinBüttner, this answer is only intended to cover the string ignoring described in the question. If you want to solicit opinion on if(0)var="this string is a comment", feel free to post an answer which expresses an opinion on how that case should be handled. – Peter Taylor Jan 9 '15 at 12:23
• A sequence of decrements and increments that cancel each other out is dead code. Choosing the right order is able to store entropy. Should the specific sequence of increments and decrements be considered a comment? Or rather, are you asserting that dead code == comment? – John Dvorak Jan 9 '15 at 12:26
• @JanDvorak, I'm more interested here in simple loopholes than in abstract philosophy. In particular, I'm not trying to do something which I've stated is impossible, but rather to justify a position on a particular specific case. – Peter Taylor Jan 9 '15 at 12:34
• I may have misread your answer as stating that every "range of characters which doesn't affect execution". Can you reformulate to state exactly the extent of your ruling? – John Dvorak Jan 9 '15 at 12:38

# This topic does not suit a general default answer

For some cases it is useful to define defaults so that questions do not need to include the same boiler plate rules every time. For example "Default for Code Golf: Input/Output methods" and "Default for Code Golf: Program, Function or Snippet?". A question can override these defaults, but having the defaults means most questions can be shorter.

I don't think this is one of those cases. There are several reasons for restricting comments and not all of them suit the same rule. This is a case where individual questions should carefully define what it is that they are excluding.

I think with this question we have arrived at a certain type of loophole. It cannot be classified with just one approach and defining the complete spec of this loophole is not that straightforward.

While I am totally up for defining a spec and banning the whole set, targeting a specific answer (what you are doing here) , which is targeting a specific answer and a specific use case (and stating that anything other than that is not being targeted here) is unjust and wrong.

As I have already said in comments, using string and popping it in CJam is just an approach to the idea. If you target that specific approach, nothing is stopping me or others to simply replace that approach with any other similar ones.

• I'm not targetting a specific answer, but a specific technique. The specific answer motivated me to start this discussion because it used that technique after I'd decided not to submit an answer to the question using the technique because it would be against the spirit of the question. – Peter Taylor Jan 9 '15 at 14:24
• As for similar approaches: feel free to enumerate them so that people can discuss where the line should be drawn. – Peter Taylor Jan 9 '15 at 14:25
• That is almost same. I am not against you targeting my question, but against you targeting a specific approach only. – Optimizer Jan 9 '15 at 14:25

In computer programming, a comment is a programming language construct used to embed programmer-readable annotations in the source code of a computer program.

Following this definition, the example could be considered as a comment. However you could use a other definition. The free dictionary defines a programming comment as:

A string of text in a program that does not function in the program itself but is used by the programmer to explain instructions.

The CJam example is definitely understood and executed by the interpreter, so you could say it's not a comment. But this is controversial: e.g. in python, a multiline comment and a multiline string is the same (triple quotes). So in my opinion a string can be considered as a comment if it's used as a comment (what doesn't make it a comment of course).

But why are comments banned in these questions? Because they allow for quick unused code. And string-comments are used exactly for this reasons so it sounds reasonable to ban them, regardless of the fact if they're comments or not. However, to me, banning strings seems not only ambiguous but also unnecessary. The use of eval statements is what makes this abuse possible (in my question at least). So while you could consider the CJam string-comment as a comment, the things that actually should be banned are the things that make comments executable.

This of course doesn't apply to polyglot challenges, here comment-like string use should be explicitly forbidden.

I won't ban eval/exec-like functions in my question (it's used in the other answers too), but I think it's the best approach to avoid loopholes.

• I'm not very familiar with CJam, but I think Optimizer's solution could be tweaked to work without eval (~), by using something like L;"'edoced;;"'";;encode'";L. In fact, I just tried this, and it works. – Ilmari Karonen Jan 11 '15 at 22:24