3 ms·
Always leave a trailing comma in Python lists, dicts, tuples
- willsmith72 3y agoSame for kotlin, javascript, probably others. I'm always shocked at people's resistance when I suggest this. To some people, commas are the hill to die on, and seemingly not for any reason except "that's how we've always done it".
- behnamoh 3y agoFor the same reason, I now prefer this foo { ... } to this foo { ... }
- jjgreen 3y agoI'd say the reason is that programming languages are based on natural languages, and in English, lists do not end with a comma.
- willsmith72 3y agoi hope we never see a programming language add an "and" between the last and 2nd last arg.
- jjgreen 3y agoThen we'd have the Oxford comma problem: [1, 2, 3 and 4] or [1, 2, 3, and 4]
- version_five 3y agoWhen I'm working on a function that I think I'll add more arguments to, or have a list I think I'll add more items to, I do this just so I don't have to modify the line above where I'm adding something (because I often end up forgetting the comma otherwise). It's interesting to see it pointed out that this helps with diffs.
- selectnull 3y agoThere is a diff tool called difftastic: https://github.com/Wilfred/difftastic https://github.com/Wilfred/difftastic The idea is that it does not show diff based on text change, but on syntastic meaning. For that, it uses tree-sitter. I think it still shows the trailing comma in the situation as shown in the article, but it's quite different experience than the standard text based diff.