Search code examples
commentsmultilineelixir

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?


Solution

  • 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