[erlang-questions] Simple multi-case

Roger Larsson roger.larsson@REDACTED
Mon Nov 13 09:48:32 CET 2006


On Monday 13 November 2006 06:41, datacompboy wrote:
> >> Since there more than one call, but too small code to move it
> >> into separate fun.
> >
> > There is no such thing as code that is too small to move into a separate
> > function.
>
> separate function -- more chars to type, and code far from table itself.
> separate function is not a problem to speed of runtime, but that problem
> for development speed. 

Most code is typed only once but read many times...
There might be a reason why both functions needs to be run - why?
Put the reason somewhere in the code.

> I need at least create new function name, that must 
> contain info about "what doing here", but not "how it doing that", since
> after some changes name will be wrong...

Do you have a corporate policy that every functions needs to have full 
documentation? Then it might be the policy that is in error...

doXZ()->doX(), doZ().

Might not be necessary to document with 20 lines of comments...

>

What about using funs? Light weight separate functions :-)

-module(test).
-export([doTest/1]).

doX()->io:fwrite("X").
doY()->io:fwrite("Y").
doZ()->io:fwrite("Z").

doTest(Id)->
  DoXZ = fun () -> doX(), doZ(), ok end,
  case Id of
     free -> DoXZ();
     online -> DoXZ();
     busy -> doY()
  end.


/RogerL



More information about the erlang-questions mailing list