Defensive Programming

Henning Diedrich hd2010@REDACTED
Mon May 17 00:04:28 CEST 2010


Hi list,

I have a question about the Erlang way.

I realize I keep programming defensive using exceptions/error calls to 
*label failure* more precisely.

E.g. ( - PRESUMABLY WRONG - )

login(Name, Password) ->

       ...
        case
                gen_tcp:send(Socket, term_to_binary(Str)) of
                     ok -> ok;
                     _ -> erlang:error(*sending_failed, {Str }*)
       end
       ...

Instead of simply

login(Name, Password) ->

       ...
        ok = gen_tcp:send(Socket, term_to_binary(Str)),
       ...


It feels wrong in Erlang and I wonder if I am missing out on something.

If somebody has a pointer to read up on this, thanks in advance,

Henning


More information about the erlang-questions mailing list