[erlang-questions] A style question

Richard Andrews bflatmaj7th@REDACTED
Fri Feb 12 10:18:41 CET 2010

On Fri, Feb 12, 2010 at 3:34 PM, Richard O'Keefe <OK@REDACTED> wrote:
> I've been looking at some Erlang code that's full of stuff like
>        F = fun() -> ...
>        mnesia:transaction(F)
> My preferred style for this would be
>        mnesia:transaction(fun () ->
>            ....
>        end)
> which I think a Smalltalk or Ruby programmer would also prefer.
> But is this just prejudice on my part, or is there a reason why
> inserting an opaque name like "F" is a good idea?

Ignoring the mnesia-specific part...

Clarity. One of my mantras of coding is: "if it's not obviously right
then it's probably wrong".

I find the former preferable when fun() is large or bulky. Inline fun
can make it unclear what the code is supposed to do.

The other reason I use the former is to give the fun a useful name
which (again) makes the code operation/goals clearer (ie.

More information about the erlang-questions mailing list