[erlang-questions] Package Support/Use

Richard Carlsson <>
Mon Nov 6 12:22:25 CET 2006


Bengt Kleberg wrote:
> you are correct. from the ''CONVENTIONS'' file:
> 
> 		- A function should *not* return wrapped values like
> 		  {ok,Value}/{error,Reason} to indicate success or
> 		  failure. The assumed behaviour should be success,
> 		  and failures should be signalled by exceptions,
> 		  as described below.

A clarification: the mentioned file was part of my attempt to rewrite 
the standard libraries (but I only got as far as reorganizing the 
existing functions). It is not part of the Erlang distribution, with the 
exception that the alternative (packaged) names for all built-in 
functions can be used, unofficially; e.g., erl.lang.list:length/1. This 
remains experimental.

Furthermore, the quoted statement needs to be qualified along the lines 
of what R. O'Keefe mentioned: exceptions should be used for conditions 
that are exceptional. There will always be a grey zone here, since it 
depends on how the function is used, so one needs to consider carefully 
what the _common_usage_ of the function will be. If you usually would 
write code that does not bother to handle the special cases - or that 
couldn't do anything meaningful even if you would like it to - then the 
special cases should probably be signalled using exceptions. If the code 
would typically always check for the special case anyway (regardless of 
how it is implemented), it should probably be handled by a special 
return value (e.g., if you have something like an iterator, you'd 
usually need to check if the end has been reached). End-of-file is 
definitely in the grey area, since many, but far from all read 
operations will read until eof.

     /Richard




More information about the erlang-questions mailing list