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

Richard A. O'Keefe ok@REDACTED
Mon Sep 25 23:27:48 CEST 2017



> 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.

What others have written about this is excellent.
When the original poster talked about 'case', I
presumed that the original code had *multiple*
success clauses in the 'case' forms, and that
single success clauses were being shown simply to
keep the example short.

If that's not so, then indeed the "keep the happy
path clean" approach is definitely the way to go.




More information about the erlang-questions mailing list