7
\$\begingroup\$

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?

\$\endgroup\$
  • \$\begingroup\$ 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. \$\endgroup\$ – Optimizer Jan 9 '15 at 11:50
  • \$\begingroup\$ 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. \$\endgroup\$ – Optimizer Jan 9 '15 at 11:51
  • 3
    \$\begingroup\$ @Optimizer It's the case for a block comment though. \$\endgroup\$ – Martin Ender Jan 9 '15 at 11:52
  • \$\begingroup\$ What about var thisVariableNameIsNotReallyUsedButItStillProvidesFreeSpaceToStashEntropyIn? \$\endgroup\$ – John Dvorak Jan 9 '15 at 12:02
  • \$\begingroup\$ @JanDvorak, I don't understand the question. If you're stashing entropy, then isn't it a completely different scenario? \$\endgroup\$ – Peter Taylor Jan 9 '15 at 12:17
  • \$\begingroup\$ 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? \$\endgroup\$ – John Dvorak Jan 9 '15 at 12:19
4
\$\begingroup\$

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.
  • Asking for polyglots with no dead code in any language is much harder than asking for polyglots with no comments.
  • 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.
\$\endgroup\$
  • 1
    \$\begingroup\$ What about var thisVariableNameIsNotReallyUsedButItStillProvidesFreeSpaceToStashEntropyIn? - is that a comment? \$\endgroup\$ – John Dvorak Jan 9 '15 at 12:03
  • 1
    \$\begingroup\$ What about "str1""str2"\;;? (push two strings, then discard them in reverse order)? \$\endgroup\$ – John Dvorak Jan 9 '15 at 12:05
  • 1
    \$\begingroup\$ As said by Martin in chat too. This is a very very broad area and simply cannot be restricted like its a duck. \$\endgroup\$ – Optimizer Jan 9 '15 at 12:09
  • \$\begingroup\$ @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. \$\endgroup\$ – Martin Ender Jan 9 '15 at 12:13
  • \$\begingroup\$ @MartinBüttner my comment says "simply cannot be restricted like its a duck" . I never said that you are denying or not. \$\endgroup\$ – Optimizer Jan 9 '15 at 12:14
  • \$\begingroup\$ @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. \$\endgroup\$ – Martin Ender Jan 9 '15 at 12:17
  • \$\begingroup\$ @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. \$\endgroup\$ – Peter Taylor Jan 9 '15 at 12:20
  • \$\begingroup\$ 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? \$\endgroup\$ – John Dvorak Jan 9 '15 at 12:22
  • \$\begingroup\$ @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. \$\endgroup\$ – Peter Taylor Jan 9 '15 at 12:23
  • \$\begingroup\$ 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? \$\endgroup\$ – John Dvorak Jan 9 '15 at 12:26
  • \$\begingroup\$ @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. \$\endgroup\$ – Peter Taylor Jan 9 '15 at 12:34
  • \$\begingroup\$ 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? \$\endgroup\$ – John Dvorak Jan 9 '15 at 12:38
2
\$\begingroup\$

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.

\$\endgroup\$
1
\$\begingroup\$

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.

\$\endgroup\$
  • \$\begingroup\$ 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. \$\endgroup\$ – Peter Taylor Jan 9 '15 at 14:24
  • \$\begingroup\$ As for similar approaches: feel free to enumerate them so that people can discuss where the line should be drawn. \$\endgroup\$ – Peter Taylor Jan 9 '15 at 14:25
  • \$\begingroup\$ That is almost same. I am not against you targeting my question, but against you targeting a specific approach only. \$\endgroup\$ – Optimizer Jan 9 '15 at 14:25
1
\$\begingroup\$

Let's start with the definition of a comment on wikipedia:

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.

\$\endgroup\$
  • \$\begingroup\$ 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. \$\endgroup\$ – Ilmari Karonen Jan 11 '15 at 22:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .