[erlang-questions] DRY principle and the syntax inconsistency in fun vs. vanilla functions

Michael Turner michael.eugene.turner@REDACTED
Thu May 19 12:47:50 CEST 2011


"But how interesting is whether existing code would break or not?"

Not very. I mean, who uses Erlang for anything important? Hardly anybody,
right?

[/sarcasm]

"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."

It would only be harder ("much"??) if you *chose*, in such cases, to use the
syntax I propose to bring over from multi-clause funs. In the case you bring
up, it might be wiser not to. And what I propose clearly allows everyone to
continue with the present syntax. So your argument for readability in this
case comes down to "somebody might not use this language feature wisely."
(*facepalm*).

-michael turner

On Thu, May 19, 2011 at 6:37 PM, Raimo Niskanen <
raimo+erlang-questions@REDACTED> wrote:

> 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
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20110519/c7f6bbed/attachment.htm>


More information about the erlang-questions mailing list