[erlang-questions] Multi-line comments in Erlang

Richard O'Keefe ok@REDACTED
Thu Dec 9 02:19:38 CET 2010

On 9/12/2010, at 3:39 AM, David Mercer wrote:

> On Tuesday, December 07, 2010, Richard O'Keefe wrote:
>> Nesting comments are one of those clever ideas
>> that turn out to be really dumb, because they don't actually work.
> I'll bite, mainly because I've sometimes thought nesting comments would be
> helpful, for instance, when commenting out large blocks of code, but it is
> rare that I get to work with a language that supports them.  Since you're
> almost always right about such things, why do you say that they don't
> actually work?

Here is a Haskell example.  Something very like this actually bit me.

	comment_close = "-}"

Comment that out:

	comment_close = "-}"

OOPS!  The comment ends at the first -}, not the second.

Before you say "but the first -} is in a quoted string",
recall that nesting comments are completely general, they are
NOT limited to escaping valid syntax in the programming language
in question.

I define "work" in this context as "you can comment out an
arbitrary chunk of text without having to worry about what is
inside it".

My text editor has a "comment out region" command that
handles comments of the form LX ... XR.  What it does is
to add extra spaces around Xs, so that this example
would be treated as

	comment_close = " - }"

and the "comment in region" command deletes single spaces
on either side of an X.  This *does* work, because it
guarantees that LX or XR brackets will never be found
inside the comment.  But that means it doesn't *need* nesting
comments at all.

More information about the erlang-questions mailing list