[erlang-questions] Package Support/Use

Christian S chsu79@REDACTED
Mon Nov 6 13:36:21 CET 2006

On 11/6/06, Olivier Sambourg <olivier.sambourg@REDACTED> wrote:
> You could also use an assertion macro (which was suggested to me a while
> back on this list):
> ?match({ok,FD}, open(Name), open_file_error),
> ?match({ok,Data}, read(FD), read_data_error),
> etc.

And just look how pretty the code is! :)

> >   {ok,FD} = open(Name),
> >   {ok,Data} = read(FD),
> >   {ok,PD} = process_data(Data),

I dont mind intermediate variables at all when they can be given useful names,
I find that they double as comments then. Plus,... I type faster than
I code. The fact that badmatch exceptions have less information
(source location!) than one would desire is unfortunate (not
changeable due to backwards compat?).

As for what is truly exceptional and what isn't: I think it is the
choice of the programmer to pick what "story" he/she wants to present:

If the code above takes a wiki page name from the user, tries to
find/open it and then parse it for a web presentation, then it isnt so
exceptional if the page doesnt exist. I would like to claim that a
nonlocal exit using exceptions would make the intent of the code
harder to read if open threw an exception.

If the code instead opens a file using a name that was stored in an
ets table, a table with the intent that all filenames in the table
exist in the filesystem. Then it really is an exception if the file
cant be opened. Deciding what error handling to do at the point 'open'
returns is difficult and one better jump directly to the exception
handler from inside 'open'.

I reject neither exceptions nor tagged tuples, I want both as options
in the standard libraries.

More information about the erlang-questions mailing list