Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiline comment in Elixir

Most languages allow block comments, and multiline commands.

For example, a multiline comment in HTML looks like the following:

<!--  Warning, brave programmer: Here be dragons. --> 

In Elixir, the closest thing I have found comes from EEx (docs).

EEx smartengine <% #comments %> seem to be discarded from source, even if they are multiline. However, this is just a workaround.

Does Elixir have a multiline comment feature, or a way to instruct the compiler to discard text from the compiled .beam file?

like image 267
Nathan Basanese Avatar asked Jun 10 '15 06:06

Nathan Basanese


People also ask

How do you comment out in Elixir?

Comments in Elixir, as is common in languages that can function as scripting languages, use the pound sign. Formally, there's no way to have a multiline comment, but a multiline string will end up being a noop.

What is Multiple comment?

Multiline comments are used for large text descriptions of code or to comment out chunks of code while debugging applications. Comments are ignored by the compiler.

How do you comment multiple lines in Java?

Multi-line comments start with /* and ends with */ . Any text between /* and */ will be ignored by Java.


2 Answers

Elixir does not have multiline comments.

However, one very common use case for multiline comments is documenting modules and functions, for which you can use the module attributes @doc and @moduledoc together with heredocs.

defmodule MyModule do   @moduledoc """   This module is great at X   """    @doc """   Frobnicates the given string.   """   def frobnicate(s) do   end end 
like image 95
Patrick Oscity Avatar answered Sep 25 '22 17:09

Patrick Oscity


Macros could help here to some degree:

defmodule Comment do   defmacro comment(_text) do   end end  defmodule TestComment do   import Comment    comment """   Module   Comment   """    def func do     comment """     Function     Comment     """   end end 
like image 29
Dimagog Avatar answered Sep 24 '22 17:09

Dimagog