treffynnon/sqlstyle.guide

Comma before the column field?

Emwat opened this issue · 3 comments

Emwat commented

I haven't read the book, but shouldn't you insert commas before the column name?

 SELECT tableID
      , first_name
      , last_name 
     --, middle_name

If you need to comment out the last line, you don't have to implement a new comma. And as a plus, all of the commas are neatly lined up.

Using leading commas makes diffs easier to read and reduces merge conflicts because only a single line is involved in adding or removing a field from a query. Doing so has made a practical measurable difference for my team. This is a more compelling argument than the convenience of commenting out fields.

With all due respect (and gratitude to you for putting this together in the first place), the argument that the approach fails for the first item is weak. A solution that works almost every time is far better than nothing!

The argument about preferring to stick to reading conventions is weaker. It's arbitrary and comes down to personal preference.

Another argument in favor of leading commas comes from your own article:

Comma positioning

So many people took issue with this - they desperately wanted commas before terms.

It's a popular request! Give the people what they want!

Your only reasons for not including this are a preference for reading conventions and a concern that it only helps most of the time, but not all of the time. I think the arguments for leading commas are compelling. I hope you'll reconsider.

Either way, cheers and good on you for putting this together. I'm happy to fork it and make the changes as I see fit.

Sorry, but what are you hoping to achieve here? This a topic that was decided long before this guide even existed.

Judging by the bulk of your fallacy laden argument you seem to have missed the clear examples of how both methods equally suck from a technical point of view. There is no functional difference in diffs, parsing, etc. Knowing this we then decide on the convention by what does differentiate them - legibility. Simple, done, the end - move on.

Just because proponents of a certain change request are noisy doesn't mean that they are right or even popular or more numerous than those that use the correct style as elucidated in the guide.

Finally, enjoy.