6 ms·
Leading with commas makes it easier to refactor if you're prototyping a query. You're less likely to cause an error when removing a column from: SELECT
by harterrt 10y ago
Leading with commas makes it easier to refactor if you're prototyping a query. You're less likely to cause an error when removing a column from:
SELECT
first
, second
, third
...
than from
SELECT
first,
second,
third
...
Which becomes:
SELECT
first,
second,
...
- ckastner 10y agoAt best, that may shave off a few seconds of the time needed to refactor. The trade-off is code that is harder to mentally parse, because we are used to trailing commas, not leading commas. If you spend more time reading code than writing it (which I assume applies to the majority of development), then the trailing comma is a much, much better choice of style.
- djur 10y ago> we are used to trailing commas Leading commas and other operators are common in some languages. Haskell, for example: https://github.com/tibbe/haskell-style-guide/blob/master/haskell-style.md https://github.com/tibbe/haskell-style-guide/blob/master/has...
- Ntrails 10y agoI spend a lot of time writing ad hoc queries for analysis. That means I don't know what columns I want, I might be switching things up from aggregates to subsets and back. That's why you'll find things like: WHERE 1=1 AND a.id = 12 --AND a.Col1 > 23 AND a.Col1 = 23 Similarly the leading comma makes it faster to cut out things I'm not using anymore. Now obviously for production code you could argue my reasons are no longer valid - but probably they'll leak through because that's what all my shk hotkeys generate and I'm used to writing
- harterrt 10y agoThe time saving isn't as important as avoiding frustration in your tools. Stubbing your toe on silly problems like trailing commas breaks flow and makes exploring less fun. In my experience, these commas don't add any real meaning to the human readers. Will it really obfuscate the code for a future reader? I can imagine it can look unfamiliar and consequentially grate someone's nerves. Reminds me of the arguments around R's "<-" vs "=". I agree with the sentiment for most code, but I doubt I spend as much time reading my SQL queries as I spend writing and refactoring.
- marcosdumay 10y agoAllowing commas on the last list item makes it easier to refactor. Leading commas just shift the problem around, making the beginning of the list hard to change, instead of the end.
- harterrt 10y agoAgreed.