[erlang-questions] Compiler to warn on used underscore-variables

Felix Lange <>
Sun Jan 10 23:51:49 CET 2010


> On Tue, Jan 05, 2010 at 01:34:10AM -0700, Tony Arcieri wrote:
> }  I'm not sure what alternative you're proposing.  Would you prefer all
> }  variables prefixed with an underscore have the same semantics as '_'?
>   
> Yes.  The current behaviour, given the purpose of a underscore
> prefix, violates the principle of least astonishment.  IMHO
> 
> I know it's not going to change but having been burnt by this
> in my learning phase I still hold that opinion.

The mere purpose of the underscore prefix is to indicate that a
variable is not used while making code easier to read as well as
easier to change in the future. If you have a function foo/7 with
a clause like 

foo(_, _, _, _, Bar, _, _) -> ...;

it's pretty hard to figure out what these underscores are 
supposed to mean without looking at the other clauses.
Having the compiler warn you that the variable isn't used when you
perfectly know that because it's intended is not a viable option
either.

To my mind, properly documenting this feature is the better alternative.



More information about the erlang-questions mailing list