A programming convention

Samuel Tardieu <>
Tue Jun 11 09:17:02 CEST 2002


On 11/06, Ulf Wiger wrote:
| On Tue, 11 Jun 2002, Joe Armstrong wrote:
| 
| >Without the Q the function must work. The relationship is
| >obvious
| >
| >	lookup(Key, Dict) ->
| >	    case (catch lookupQ(Key, Dict)) of
| >		{'EXIT', Why} ->
| >			{error, Why};
| >		Other ->
| >			{ok, Other}
| >	    end.
| 
| ...Obvious, but (obviously) the opposite of the above. ;)
| 
|    lookupQ(Key, Dict) ->
|       case (catch lookup(Key, Dict)) of
|          {'EXIT', Why} ->
|             {error, Why};
|          Other ->
|             {ok, Other}
|       end.

I prefer Joe's solution: an exception should stay exceptional. The reason
for that the compiler designers may choose to make an exception handler
as cheap as possible ("zero cost") when no exception is raised, while
an exception may take a lot of time to be processed when it is raised.

Obviously this is not true in the current Erlang implementation, but may
become true if Erlang gets compiled to native code with table-driven
exceptions, whose setup cost is virtually zero and propagation time very
high.

  Sam




More information about the erlang-questions mailing list