[erlang-questions] (no subject)

Jay Nelson jay@REDACTED
Mon Mar 10 18:50:05 CET 2008

Georgy wrote:

 >  Jay wrote:
 > > The main point is that it is error prone to rely on all branches  
of a
 > > case to set variables which are used later.

 > Why? The compiler helps you notice when one is missing.
 > Complains like this (error message, not warning):
 > variable 'X' unsafe in 'case' (line XXX)

 > Jay wrote:
 > > Better to make it
 > > explicit and let the compiler help you notice when one is missing.

 > For that reason I don't understand this.

I stand corrected.  I wasn't aware of the compiler error because I  
avoid that style of code.

The reason I avoid it, is that I find it more difficult to visually  
verify in the editor.  Also, if more clauses are added in the future,  
you have to keep track that the following code relies on setting some  
variables (or else, apparently, wait until you compile to notice you  
need some others).

I just find that the following style:

{ ... args needed ... } = compound statement,
use args

advertises the programmer's intent much more clearly.  It states that  
the compound statement is being executed for the side effect of  
binding a particular set of variables.  This binding environment is  
necessary for the following statements.  It corresponds to a (let  
(...) ...) clause in lisp.


More information about the erlang-questions mailing list