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

Steve Strong <>
Thu May 19 11:02:20 CEST 2011

I hadn't taken the time to do the exercise myself, but your results don't surprise me. Although repeating the function name doesn't strictly comply with DRY, I personally think that it improves readability of all but the most trivial examples. And, for me at least, readability trumps pretty much every other principle (outside of correctness, obviously). DRY is an important concept but, as with most such things, you need to know when to stop, and for me this would be a step too far. 

If I took some (most) of my gen_servers and removed the text "handle_call" from all but the first clause, navigating the code would become significantly harder. A simple search would not jump me between clauses, I would instead need to rely on tool support for this very common use-case.

Obviously, readability is a subjective thing and others may disagree. But if I had a vote, then I think there are other areas of the language where minor tweaks would have much greater benefits, such as allowing trailing commas on lists as Joe raised earlier. I understand that your suggestion would allow both options, but unless the compiler team have infinite resources then I would put non-duplication of function names pretty near the bottom of the todo list.

As others have said, if this is such a big thing for you, then write a front-end to do the transform…



Steve Strong, Director, id3as
On Thursday, 19 May 2011 at 10:48, 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?
> On 5/19/2011 3:32 AM, Steve Davis wrote:
> > Hi Michael,
> > 
> > This example is far from convincing. Have you tried this for yourself on
> > any but the most trivial case, and done a genuine comparison? If you
> > had, I think you would actually agree with my point that it would end up
> > being less readable.
> > 
> > regards,
> > /s
> > 
> > On 5/18/2011 11:28 PM, Michael Turner wrote:
> > > Brokenness is not the only fault a system can have. As far as I can
> > > tell, the worst consequence of the proposed change is that you'd start
> > > seeing code that looked like this:
> > > 
> > > fact
> > > (0) -> 1;
> > > (N) -> N*fact(N-1).
> > > 
> > > which is transparently obvious. So the argument that the change somehow
> > > makes code less readable makes no sense to me.
> > > 
> > > -michael turner
> _______________________________________________
> erlang-questions mailing list
> http://erlang.org/mailman/listinfo/erlang-questions
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20110519/e190c25a/attachment.html>

More information about the erlang-questions mailing list