[erlang-questions] preferred looping style

Jesse Gumm <>
Wed Jun 22 19:47:48 CEST 2011


Style 2 certainly looks cleaner to me, and that's the way I tend to prefer.

And beyond that, it removes the conditional from every iteration.

-Jesse

On Wed, Jun 22, 2011 at 12:44 PM, Icarus Alive <> 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
> 
> http://erlang.org/mailman/listinfo/erlang-questions
>
>



-- 
Jesse Gumm
Sigma Star Systems
414.940.4866

http://www.sigma-star.com



More information about the erlang-questions mailing list