'_ = some_function_call' necessary?


I have come across some elixir repos recently and have noticed “_ = <some_function>” getting used in the code. For example

_ = File.read("some_path")

Is this a convention? I have heard some people say it denotes that we are aware of a return value of a function, but are signifying that we don’t care about it. But I would have thought that just calling the function with no LHS assignment would have been enough for that.

Am I correct in saying this is unnecessary, or is there in fact some meaning to it that I am unaware of.



There’s a dialyzer setting to warn on unused return values and sometimes not handling a return value can be a source for bugs. It might be unnecessary, but still has usefulness beyond the raw functionality of the code.


_content = File.read(...) would be much clearer imo.