[erlang-questions] Nested Case Statements v.s. multiple functions

Richard A. O'Keefe <>
Mon Sep 25 23:20:02 CEST 2017




>  send_update(Arg1) ->
>      case ... of
>          {ok, [Val1, Val2]} ->
>              send_update(check_indices, {Arg1, Val1, Val2});
>          Else ->
>              lager:error("ERROR: ..")
>      end.
>  send_update(check_indices, {Arg1, Arg2, Arg3}) ->
>      case check_indices(Arg2, Arg3)of
>          true ->
>              send_update(get_values, {Arg1, Arg3});
>          false ->
>              lager:error("EMERGENCY: ….")
>      end;

Why is this not

     send_update(Arg1) ->
         case ...
           of {ok, [Val1, Val2]} ->
                  check_indices(Val1, Val2, Arg1)
            ; _ ->
                  lager:error("ERROR: ...")
         end.

     check_indices(Val1, Val2, Arg1) ->
         case check_indices(Val1, Val2)
           of true  -> get_values(Val2, Arg1)
            ; false -> lager:error("EMERGENCY: ...")
         end.

When you break a large function into lots of little
functions, the little functions should have their
own names and their own comments.


More information about the erlang-questions mailing list