
Leading with commas – ugly or efficient? An investigation over 320GB of SQL - danso
https://towardsdatascience.com/winning-arguments-with-data-leading-with-commas-in-sql-672b3b81eac9
======
Jeff_Brown
That this has three lines could not be easier to see:

    
    
      [  la la la la la la la la la la la
      ,  la la la la la la la la la la la 
         la la la la la
      ,  la la la la la la la la la la la 
         la la la la la la la la la la la ]
    

Seeing that in this requires a little more work:

    
    
      [  la la la la la la la la la la la,
         la la la la la la la la la la la 
         la la la la la,
         la la la la la la la la la la la 
         la la la la la la la la la la la ]
    

In real-world code, the lists might be of expressions that can themselves
contain commas, and the lines can be longer and more heterogeneous. All of
those factors make the leading comma idiom even more readable relative to the
trailing one.

------
innagadadavida
It is easier for normal humans to read trailing commas, but difficult to
change during development. If you are actively developing a query, perhaps you
could just add a dummy column:

SELECT a, B, c, 0 ...

------
sneak
I like Go’s solution: mandatory trailing commas. Doesn’t work for set-in-stone
sql, sadly.

~~~
DannyB2
Java, in a few places, has optional trailing commas. That is, if your last
item also has a trailing comma, that is okay.

To put this into SQL notation:

SELECT col1, col2, col3, FROM Table

Now the columns were on separate lines, it is easy to comment/uncomment, or
copy/paste columns around. just write every column with a comma at the end.
But not in SQL -- just in various places in Java code. But I wish that were in
SQL.

In Java enums are the first that immediately comes to mind. Every item can
have a trailing comma. After the final item (and its optional comma) use a
semicolon to begin class level declarations for the enum (if any) such as a
custom constructor.

In Java, another example is array initializers:

int[] values = { 1, 2, 3, 4, 5, };

If those initializer items were on separate lines, it is easy to
comment/remove/interchange rows because they ALL have a comma.

------
londons_explore
Do the results stay the same if you exclude files longer than say 1000 lines?

I think a lot of big .sql files in repos might be autogenerated by tools, and
being long would be a good way to remove some of them.

------
geordee
I prefer leading with commas, and one column per line.

------
quantified
Another argument for designing languages and formats so that there is no need
for the comma.

