[erlang-questions] Reassigning variables

mats cronqvist <>
Wed Mar 18 11:44:54 CET 2009


bill robertson <> writes:

>>  So I think the X1 = f(X), X2 = f(X1) anti-pattern is not a weakness
>>  of the language; it's Erlang's way of telling you that you should
>>  use more functions.
>>
>>  mats
>
> This is an honest question.  How is re-assignment of local variables
> bad?

  it is also easier to debug code with many small functions, because
  of the trace functionality. E.g. using redbug, a small wrapper
  around erlang:trace/trace_pattern;

  105> redbug:start(10000,20,{erlang,now}).
11:38:51 <timer_server> {erlang,now,[]}
11:38:51 <timer_server> {erlang,now,[]}
11:38:51 <kdb_sync> {erlang,now,[]}
11:38:52 <{yaws_server,gserv,3}> {erlang,now,[]}
11:38:52 <{yaws_server,gserv,3}> {erlang,now,[]}

  Basically, it's like having a printf at every function head.

  The trace function alone is reason enough never to number variables,
  nest cases or anything else that promotes large functions.

  mats



More information about the erlang-questions mailing list