[erlang-questions] DRY principle and the syntax inconsistency in fun vs. vanilla functions
Raimo Niskanen
raimo+erlang-questions@REDACTED
Thu May 19 11:37:46 CEST 2011
On Thu, May 19, 2011 at 01:50:33AM +0900, Michael Turner wrote:
> I'm still waiting for the answer to the real showstopper question: would any
> existing code break, under my proposal?
>
> -michael turner
>
I can not think of any existing code that would break, but there
are others that have weirder imagination than me.
But how interesting is whether existing code would break or not?
One nice thing with Erlang for me is that it is not like Perl;
there seldom seldom many ways to do it (syntacticly).
The current compromise and limitation of having to write the
function name for every clause for regular function and not writing
any function name for funs I think is very good. It encourages
short funs and makes it easier to read long functions with
many clauses. If you restructure your code, move around clauses
often you run into a compilation error when you have messed up
clauses between functions.
If you would remove the requirement of a function name on every
clause you would increase the possibility of getting completely
incorrect code through the compiler since it is enough that
the arity is the same between the clauses; you can accidentally
paste in a totally unrelated clause from some other function
and not discover it until it crashes in the field, provided
testing is incomplete (which it mostly is).
It would, as others have pointed out, also be much harder to
jump into a module and _know_ what the clause does since
the function's name can be pages away. That would encourage
no more than page-long functions instead of no more than
page-long clauses and I sincerely prefere the latter.
In short. I think the impact on readability and programmer's
common mistake preventions clearly does not motivate the change.
The possible benefits are minor.
--
/ Raimo Niskanen, Erlang/OTP, Ericsson AB
More information about the erlang-questions
mailing list