[erlang-questions] DRY principle and the syntax inconsistency in fun vs. vanilla functions
Richard O'Keefe
ok@REDACTED
Mon May 23 04:23:50 CEST 2011
On 21/05/2011, at 2:11 AM, Michael Turner wrote:
> "It seems to me that Michael Turner's argument is an argument from conservatism.
> Algol, Basic, COBOL, Fortran, PL/I, Simula, XPL, Java, Javascript, PHP, Perl,
> all of these languages write a function name once and only once at the beginning
> of a function."
>
> But which of those allow more than one argument list?
It's not quite clear to me what you mean here, but
add(x)to:(y)giving:(z)and:(w)
is perfectly good Algol 60. Javascript allows things like f(1)(2).
And of course, anyone who knows Fortran knows that a Fortran subprogram
may have multiple entry points, and so multiple formal parameter lists.
If you mean "allow more than one CLAUSE", then the answer is that the languages
that allow more than one clause in a named function repeat the name, just like Erlang.
> I think the indentation style I suggest also makes it more immediately obvious that Erlang features a kind of pattern-directed invocation.
People who are entirely new to Erlang are also entirely new to the idea of pattern directed
invocation, and if they aren't, they are also not new to the idea of repeating the function
name. If you are new to pattern directed invocation, your indentation is not going to help
one iota: one left parenthesis or square bracket looks much like another.
I will go this far: the discrepancy between functions and funs *is* a problem.
But it is the *funs* that are the problem, and the remedy is to let them have
names also.
Allowing names in funs is not a case of syntactic strychnine; not even a case
of syntactic sugar. It actually provides new and desired semantics (directly
recursive funs), so it is at least _possible_ that it might repay the cost of
adopting it. As things stand, I must say that I find multiclause funs in the
usual indentation style (that is, in the indentation style you are recommending
for normal functions) quite unreadable.
>
> As for what you claim is more readable, remember: the intuitive is the familiar. Someone who is entirely new to Erlang will perceive things differently.
The people who actually *teach* Erlang to people who have not met us before
tell us that they actually pick it up fairly easily.
> The only way to make the proposition "syntax X is more readable" a scientific one is to test -- on people *new* to Erlang.
Wrong. What a tricky way to load the case in your favour!
The people who are entirely new to the language are the very LAST people you should
study; then you are measuring LEARNABILITY (or more FAMILIARITY), not READABILITY.
The kind of readability that matters is readability to people who have *some*
experience with the language. People who have at least troubled to read an
Erlang book all the way through, and can be bothered to read the Erlang
reference manual once all the way through. By the time you get that far,
you are not "entirely new" any more.
I can tell you this: I went from knowing practically all the classic 60s and 70s
programming languages (including ones you've probably never heard of), including
Lisp, to learning Prolog.
And one thing that never EVER gave me the slightest trouble whatsoever was having
the name of a predicate repeated in each clause.
More information about the erlang-questions
mailing list