Erlang question on Artima blog

Shawn Pearce spearce@REDACTED
Sun Mar 14 00:13:40 CET 2004


Ulf Wiger <ulf.wiger@REDACTED> wrote:
> 3) Erlang doesn't really use Design by Contract, but relies
>    rather heavily on pattern matching. For example,
>    The function file:open(File, Mode) is defined so that it
>    returns {ok, FileDescr} or {error, Reason}. A typical
>    call to this function would be formulated:
> 
>    {ok, Fd} = file:open("foo.txt", [read]).

And yet I seem to write:

	case file:open(...) of
	{ok, Fd} ->
		Ret = do_something_with_file(Fd),
		file:close(Fd),
		Ret
	Other ->
		Other
	end.

much more often.  Help, what is wrong with me!  :-)

-- 
Shawn.



More information about the erlang-questions mailing list