Erlang question on Artima blog

Ulf Wiger <>
Sun Mar 14 09:31:16 CET 2004


On Sat, 13 Mar 2004 18:13:40 -0500, Shawn Pearce <> 
wrote:

> 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!  :-)

Oh, don't worry. It's a mild affliction. (:

I think writing code that either does what it's supposed
to or exits is an acquired taste, and you grow into it slowly
once (and if!) you set your mind to it. You need to sit down and
really think about how and where you want to handle errors in
your code.

Personally, I think "programming for the correct case" has
significantly improved the readability of my own programs
(at least my own ability to understand what I've written.  ;)

/Uffe
-- 
Ulf Wiger




More information about the erlang-questions mailing list