[erlang-questions] case expression scope

Anthony Ramine n.oxyde@REDACTED
Tue Mar 4 23:57:11 CET 2014


My point still stands, don’t put such complicated code in the middle of nowhere, why would you call calculate_very_expensive_default_value() here in foo/1? Put the nastiness away from main path.

-- 
Anthony Ramine

Le 4 mars 2014 à 23:55, Szoboszlay Dániel <dszoboszlay@REDACTED> a écrit :

> But what if BazDefault is based on my trusty calculate_very_expensive_default_value(), and the error would have to be logged on warning level with a different format string? :P
> 
> Daniel
> 
> On Tue, 04 Mar 2014 23:48:43 +0100, Anthony Ramine <n.oxyde@REDACTED> wrote:
> 
>> Hello,
>> 
>> This would be better written as:
>> 
>> maybe_log_error(Default, Fun) ->
>>  case Fun() of
>>    {ok,Result} ->
>>      Result;
>>    {error,Reason} ->
>>      lager:error("SOS ~p", [Reason]),
>>      Default
>>  end.
>> 
>> foo() ->
>>  ...
>>  V1 = maybe_log_error(BarDefault, fun bar/0),
>>  V2 = maybe_log_error(BazDefault, fun baz/0),
>>  ...
>> 
>> Sorry, but no luck for the filter.




More information about the erlang-questions mailing list