views:

351

answers:

7

Quick Quiz?

What language has comments with side effects? In essence, comments which are not comments...

+3  A: 

English. Do I win?

MusiGenesis
You sure do. Answering a closed question. You'd better have a talk with the person who closed the question.
Windows programmer
Nah, he's an idiot.
MusiGenesis
Your answer is 'not-programming-related' hehe
victor hugo
A: 

CSS for clever cross-browser hacks. Of course, I wouldn't really call CSS a language.

Troy Howard
I don't think interpreter implementation bugs would count.
Greg Hewgill
+2  A: 

Haskell can turn the usual comments in code paradigm upside down by having code in comments - also Mathematica and the like; literal programming is a nice feature for the more mathematically inclined languages.

I also find annotations in Java are like comments with behaviour.

Brabster
Another example of code in comments: embedding PHP or similar in an HTML comment. (Some less sophisticated syntax-highlighting editors will miss this.)
Stewart
+3  A: 

DOS Batch Shell programming

The REM (Remark) allows you to put in a comment. But it has the side-effect of modifying the ERRORLEVEL variable to 0.

In a sense, it makes last operation a success.

I don't know how a comment can fail, but if it does, you are covered.

theschmitzer
Originally, the Bourne shell did not support '#' comments; you used the ':' operator and a string for them. That would succeed, so the status variable $? would be reset to 0.
Jonathan Leffler
+3  A: 

I can think of several places where comments aren't really comments.

  • HTML and script tags (providing support for browsers that don't allow or support scripts).

And then, considerably more obscurely:

  • IBM Informix 4GL (I4GL) and 4J's Genero (successor to Informix Dynamic 4GL, D4GL). The notation '--#' was used by D4GL to include material only applicable to D4GL; I4GL would see that as a comment. The inverse notation was '--@', which looked like a comment to D4GL but was treated as active material by I4GL.

And, even more obscurely:

  • I wrote an I4GL file which was dual-languaged, exploiting I4GL's multiple comment facilities. Material starting '#' (hash) marked the start of a comment outside of strings - up to the next newline, as does '--' (double-dash). Also, '{...}' (braces) enclose multiline comments.
  • The top of the source file was actually a shell script, mostly enclosed in '{...}' which is, of course, perfectly legitimate in shell. The shell script was a data-driven code generator that copied itself to the top of the output, and then generated about 100 functions which were all depressingly similar but slightly different (in a language without templates or a pre-processor). The code had to validate what was in the database for a given ship against incoming data from an external source (Lloyds of London, in fact), to see what had changed since the last time the external data was received. Non-trivial comparison work, especially since it had to deal with database (SQL) nulls.
  • The file was not really a Quine program, but it had some points in common with it. In particular, you could feed the script broken I4GL code and the regenerated file would be perfect again, basically because it ignored the existing I4GL code.
Jonathan Leffler
+1  A: 

Then of course there are "polyglots" -- programs which can be compiled/executed in multiple languages. Usually these rely on the fact that the same line is a comment in one language, but an actual line of code in another.

MatrixFrog
+1  A: 

QBasic has a use of comments all its own: REM $STATIC or REM $DYNAMIC set how arrays are allocated.

Another example: When web browsers parse comments <!-- -- -->in<!-- -- -->correctly.

Stewart