8

After googling a bit it seems there is no multi-line comment support in Erlang, is this really the case?

And if so, why?

I know some editors support commenting out regions (adding % first on every line of the region) but i don't really want to pick editor based on this.

2
  • No, there isn't. Very often, the comments are used to generate doc, end they follow some syntax rule
    – Pascal
    Commented Aug 15, 2014 at 7:37
  • 5
    As you as you start discussing block comments you immediately run into the religious argument of whether they should be able to be nested or not. We decided not to start that argument. :-)
    – rvirding
    Commented Aug 27, 2014 at 13:40

2 Answers 2

8

It's simple. Use preprocessor:

-ifdef(comment).
  Something to comment
  You can add text or
  function(Declaration) ->
     ...
  Which will removed from file
-endif.
1
  • 1
    That might be useful sometimes, but it only enables you to comment out whole functions, attributes, etc - you can never use it inside a function or anywhere except at the top level of the module definition.
    – Michael
    Commented Jan 17, 2018 at 10:28
5

There are no multi-line comments in Erlang.

In general, I haven't found this to be a big deal: I use templates for gen_server and supervisor and a general template for other modules, and all of these include the boilerplate top doc blocks. I get some template support from my editor (Emacs) but you could be editor-agnostic and just write some templates and copy them to any new modules you want.

The biggest use of multi-line comments other than documentation is to comment-out a big chunk of code. Since your Erlang code should generally be small functions, you can just comment out the function call, which is a one-line comment.

2
  • you can just comment out the function call--What if I call the function 30 times? Or, what if I want to reimplement the definition of the function and comment out the old definition? Multi-line comments are handy in any language. Why can't %% be the delimiters for multi line comments?
    – 7stud
    Commented Sep 23, 2015 at 1:14
  • Hopefully you're not calling it 30 times in a row (you should use a loop for that), so for 30 calls scattered all over your code you'll have a pretty bad time in any language. If you want to reimplement the function, please use version control. It's so much better than dead code everywhere. Commented Sep 23, 2015 at 2:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.