[erlang-questions] eep-0012 (Extensions to comprehensions)

Richard A. O'Keefe <>
Fri Aug 8 01:11:50 CEST 2008


On 7 Aug 2008, at 5:27 pm, Kevin Scaldeferri wrote:
> The point is that you could have changed:
>
> 	   X,
> 	]
> to
> 	   X,
> 	   Y,
> 	]
>
> and then only one line changed.

That was obvious, and as my reply showed, it was clearly understood.
The NUMBER of changes is entirely unaffected.
The SIZE of the reported change increases by exactly one line,
AND that extra line helps.
If you are using context diffs, which is usually a good idea,
you probably won't even notice the extra line.

Note that the ONLY place that C allows an extra comma is in an
initialiser.  Suppose for example I have

	OLD             NEW

     void f(         void f(
         int x           int x,
                         char *y
     ) {            ) {
         ...            ...
     }              }

I added *one* parameter to the argument list of f(), but
*two* lines changed.  (For the record, whenever an
argument list in C is too long to fit on one line, this
is indeed how I lay it out.  After years of experiment,
I have to say that this seems to be the perfect way to
do it.  It also works in Java, Pascal, Ada, any free-
format language.)

It's exactly the same "problem", but do I hear lots of
complaints about C because of it?

C doesn't allow trailing commas in function calls.
C doesn't allow trailing commas in comma expressions.
C doesn't allow trailing commas in declarations:

	extern void
	    f(void),
	    g(void);
=>
	extern void
	    f(void),
	    g(void),
	    h(void);

One prototype added to the list, two lines changed.

It's exactly the same "problem", but do I hear lots of
complaints about C because of it?

Perl and Python allow trailing commas in tuples, lists,
and function calls.  In Python, the idiom (x,) for a
1-element tuple is used heavily.  Curiously, while
trailing commas in lists *are* used, they are very
often used like
	x = ["foo","bar","ugh",]
(I've just been trawling through *thousands* of Python
files) where the trailing comma does NOT help in the
way envisaged.

Python is definitely evidence that a language *can*
allow trailing commas without collapsing into an
evil-smelling heap.

Pascal, Ada, Modula-2, Fortran 90 and later, AWK,
none of these allow trailing commas.

Like C, Java allows trailing commas in array initialisers
(JLS 3rd edition, section 10.6), but not elsewhere.
I don't hear lots of people complaining about the fact
that turning
	String x,
	       y;
into	String x,
	       y,
	       z;
results in a 1-change 2-line diff instead of a
1-change 1-line diff using Java.  And Javascript is
another: trailing commas are allowed in arrays and
"objects", but not in declarations or calls.

> As I said, this is a pretty minor issue, but it's a minor issue many  
> people will mention.
>
Why will "many" people be bothered about this in Erlang,
when they apparently aren't bothered by it in C or Java
or Javascript?

Why is the "add one thing -> diff should be one line"
idea so important for changes to data constructors but
ONLY data constructors?

--
If stupidity were a crime, who'd 'scape hanging?










More information about the erlang-questions mailing list