Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Silence compiiler warning about @doc on private functions

Tags:

elixir

Elixir wants to warn me that my @doc annotations won't get copied to the beam file:

warning: function foo/1 is private, @doc's are always discarded for private functions
  lib/hello/world.ex:12

But I'd rather use @doc for all my function documentation instead of switching between @doc and #.

How can I tell the compiler to stop warning me about this?

like image 950
Nathaniel Waisbrot Avatar asked Jul 18 '17 15:07

Nathaniel Waisbrot


1 Answers

There is no way to silence compiler warnings.

In the past, people have asked about documenting private functions for use with ExDoc or DocTest. However, this not possible. Per José:

It is worth remembering that a private function does not exist outside of the module that defines it. You cannot test private functions because you can't invoke a private function outside of the module that defines it.

In fact, the compiler may even remove the private function entirely during compilation. This means a private function only exists when looking at the code and, if you need to look at the code to read it, then it is not documentation.

A private function is, for all purposes, exactly what you defined code comments to be: a temporary or semi-permanent blob which is aimed directly at developers. There is no guarantee it will exist tomorrow, which is why it is private.

like image 139
PatNowak Avatar answered Dec 04 '22 19:12

PatNowak