[erlang-questions] A style question

Richard O'Keefe ok@REDACTED
Mon Feb 15 03:06:10 CET 2010


On Feb 14, 2010, at 10:39 AM, Jayson Vantuyl wrote:

> I've always felt that "fun some_func/2" is underused.

It's a good thing to use _if_ you already have some_func/2 and
don't need to pass it any arguments.

We have agreement on a number of points.

(1) If you introduce a name for a function that is passed to
     a higher order operation, it should be a meaningful name,
     not just "F" or "f" or anything like that.

(2) If you already want to name a function for some other reason,
     use fun F/N to refer to it rather than fun (X,...) -> F(X,...) end.

(3) If the code would be bulky, _something_ has to move out and
     it might as well be the 'fun'.

(4) Having 'fun (..) -> end' available means we don't have to
     export things just so they can be called, and having
     'fun F/N' available means the same; exporting stuff we'd
     rather not is no longer an issue.

(5) If there is information in the surrounding clause that needs to
     be passed in, one level of 'fun' to capture that seems to be
     necessary, but it need not be the _whole_ of the computation;
     you can hand the information off to something with a name and
     a comment.

I think we're now pretty much down to the "personal judgement"
level.

  
   


More information about the erlang-questions mailing list