[erlang-questions] Human readable errors in lists module

Joe Armstrong <>
Fri Feb 13 17:00:23 CET 2009


Sorry the last mail got sent early

I use this idiom

 top(Arg1, Arg2) ->
     try
          begin
                  {ok, S} = foo(....),
                  {X, Y} = bar(A, S),
                  ....
          end
     catch
         _:X ->
               io:format("~p OOps~n",[X]
     end.


The code between begin and end is written with no regard to errors
the foos and bars are written with no regard to errors.

top(...) either succeed or fails with an error message.

Does that remind you of something? - It should. It's a tr.....

Think of the code as a transaction that succeeds or fails with an error message

Were did we write the unit tests and the assertions (answer: in the
pattern matches that might fail)

/Joe Armstrong

>
>
> On Thu, Feb 12, 2009 at 6:52 PM, Steve Davis
> <> wrote:
>> If you are coming from java et al. the "let it crash" style is
>> actually quite hard to get used to at first. Defensive programming is
>> a strong habit and it is a good habit when writing java/cpp etc. But
>> with Erlang, the "let it crash" style is absolutely the *right thing
>> to do*. You will soon realize that this is a liberating license to
>> write the kind of aggressive code that would love to be able to write
>> in java/php/c/younameit --- when you get used to it you will enjoy
>> programming more and will find your productivity soaring!
>>
>> /s
>> _______________________________________________
>> erlang-questions mailing list
>> 
>> http://www.erlang.org/mailman/listinfo/erlang-questions
>>
>



More information about the erlang-questions mailing list