FAQ terminology harmonisation

Rick Pettit rpettit@REDACTED
Thu Apr 3 22:07:26 CEST 2003


On Thu, Apr 03, 2003 at 09:18:46PM +0200, Matthias Lang wrote:
> not checking for "NULL" isn't quite the same as the usual erlang
> approach. The usual erlang approach is to use pattern matching to
> force an abort in many cases where something unexpected happens, e.g.
> 
>    {ok, S} = gen_tcp:connect(Host, Port, Options),
>    ...
> 
> you can't really write that naturally in C, I find myself forever
> writing
> 
>    sock = connect(...);
>    assert(sock);
> 
> Is that defensive programming? Not really, IMO. PERL has an idiom
> which is somewhat like Erlang, btw: f() || die

Not sure I completely agree here. Checking for NULL _IS_ checking for the
unexpected (you just do it more often in C/C++).  In both cases you expect the
connection to be established, and in both examples you assert that it is.

Pattern matching to force an abort (at least in this case) is just syntactical
sugar for aborting on failed assertion.

If aborting when something unexpected happens is not defensive programming, then
perhaps I have a more fundamental misunderstanding.

-Rick



More information about the erlang-questions mailing list