Variable instances (Re: Trace on Variable assignment)

Ulf Wiger etxuwig@REDACTED
Fri Nov 10 14:40:47 CET 2000


On Fri, 10 Nov 2000, Richard Carlsson wrote:

>However, a nice compromise could be to let the compiler
>warn about unused variables (when the `warn_unused_vars' option is set)
>*unless* the variable is underscore-prefixed.
>
>That means that typical errors like:
>
>		S1 = foo(S0),
>		S2 = bar(S0),
>		S3 = foo(S2),
>
>will be warned about (S1 is not used), but no complaints would be issued
>about your example {clause,_Line,[{_Type,...
>
>	/Richard Carlsson

Hmmm, I tried it on my own code. Since I've never liked the _Var
convention (since they are actually bound, something that can cause
very obscure bugs), I have lots of variables for documentation
purposes only. Relying on the compiler to eliminate unnecessary
variable bindings, I've come to do that even more.

Thus, I get so many warnings from the linter that the
'warn_unused_vars' option becomes unwieldy.


In our work on writing design rules, we've never been able to agree on
a recommendation for "don't care" variables. Some like to annotate
with underscores, others have tried it, but recoiled in horror when
they've had to chase down weird pattern-matching bugs (not
understanding from the start that they were actually binding
variables). Others, like Peter Lundell, hate "don't care" variables
(even '_' which is truly "don't care" but doesn't let you clarify
what kind of variable it should be), and never use them at all.


/Uffe
-- 
Ulf Wiger                                    tfn: +46  8 719 81 95
Senior System Architect                      mob: +46 70 519 81 95
Strategic Product & System Management    ATM Multiservice Networks
Data Backbone & Optical Services Division      Ericsson Telecom AB




More information about the erlang-questions mailing list