Favorite non-python language trick?

Duncan Booth duncan.booth at invalid.invalid
Fri Jun 24 10:56:40 CEST 2005


Uwe Mayer wrote:

>> /*
>> print(10);
>> */
>> 
>> and
>> 
>> ///*
>> print(10);
>> //*/
>> 
>> ?
> 
> I think the *trick* here was that if you had larger blocks you'd only
> have to change one side of the comment, i.e. the opening line, to
> de-comment the block without searching the end of it and commenting
> that out aswell. 

Yes, but you can do that easily in C++ as well:

/*
print(10);
//*/

Change to:

//*
print(10);
//*/

I can't remember the exact pattern, but I remember using a
similar trick in BCPL where at least there was the excuse of not
otherwise having conditional compilation. C and C++ there is no excuse
for such tricks. 

Google found Clive Feather's description of the BCPL trick at 
http://www.lysator.liu.se/c/clive-on-history.html:

> I doubt it (though DMR may contradict me, of course).  Every compiler
> I remember using allowed both // and /* */ type comment delimiters. 
> Some also allowed | and \ to be used instead of /, so that || was also
> a comment-to-end-of-line, and \* ... *\ was an alternate block comment
> symbol.  The latter was particularly useful, because it could be used
> to comment out blocks of code that included /* ... */ comments (as
> with C, comments do not nest).  We used comments with vertical bars to
> implement a variety of conditional compilation: 
> 
>	|**||| IF
> 	normal code
>	|*|||| ELSE
> 	alternate code
>	|*|||| CANCEL ELSE
> 	more normal code
>	|*|||| ELSE
> 	more alternate code
>	|**||| ENDIF
> 
> By default, this would compile the "normal code".  To switch to the
> "alternate code", the first line was changed to |**||* or |*||||
> instead.  Because this comment symbol was used, the code could contain
> normal comments and the "commenting-out" reverse comments I described
> above. 




More information about the Python-list mailing list