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

David Mercer <>
Thu May 19 18:35:14 CEST 2011

On Thursday, May 19, 2011, Steve Davis wrote:

> Out of interest, I tried it on one of my own modules.
> Your way: https://gist.github.com/980420
> The highway:
> https://github.com/komone/qrcode/blob/master/src/base32.erl
> In order to make your way less confusing, as the pattern matching entry
> points to the function were extremely un-obvious, and in the spirit of
> making it work I tried "double indent".
> Double indented: https://gist.github.com/980412
> For me, either way, the intention is harder to read, and/or forces me
> to
> focus on/put in a bunch of white space.
> What do you think?

I've got to admit: I prefer the double-indented version, especially with the
syntax coloring.  I'd probably put a newline between the function name and
the arguments of the first clause, but it did seem to make it more clear to
me which were clauses of the same function and which were a different one.

But, that being said, I still stand by my statement from the previous thread
that repeating the function name is syntactic salt that helps prevent some
errors.  As Raimo well put it later on in the thread:

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

Therefore, I do not think we need to accommodate the DRYer syntax.

Cheers, y'all!


More information about the erlang-questions mailing list