[erlang-questions] preferred looping style

Rapsey rapsey@REDACTED
Wed Jun 22 19:47:38 CEST 2011


If you are concerning yourself about 1 stack frame extra, you're using the
wrong language. Style 2 is definitely the way to go.


Sergej

On Wed, Jun 22, 2011 at 7:44 PM, Icarus Alive <icarus.alive@REDACTED>wrote:

> Hi,
>
> Of these 2 styles, which one is preferred, and why ?
> To me, the readability of 2nd style is better, tough it consumes 1 stack
> frame extra.
> Are there some cases where style-1 might be preferred, or be the only
> option ?
>
> %% style-1 -----------------------------------------
> mainLoop(InitialRun) ->
>   if InitialRun == true ->
>    % do some initialization,
>     mainLoop(false);
>  true ->
>     % do routine loop tasks,
>    mainLoop(InitialRun)
>   end.
>
> %% style-2 -----------------------------------------
> loopInit() ->
>  % do some intialization,
>   mainLoop().
>
> mainLoop() ->
>   % do routing loop tasks,
>  mainLoop().
>
>
> cheers,
> Icarus
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20110622/e0e30a7a/attachment.htm>


More information about the erlang-questions mailing list