Leading with commas – ugly or efficient? An investigation over 320GB of SQL
towardsdatascience.com
towardsdatascience.com
[ 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.SELECT a, B, c, 0 ...
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.
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.