Inconsistency: "Dangling Comma" on multiline data structures and function calls
See original GitHub issueDescription
There is a project-wide inconsistency within Sir Lancebot’s code. For multiline data structures and function calls such as
foo = [
"yeet",
"cat",
"lololol"
]
, some people think we should add a trailing/“dangling” comma at the last line while others don’t.
In the code, there are instances where the dangling comma is used and instances where it is not. This can be misleading for new people wanting to contribute (such as me, last time I was discussing with ToxicKidz and Kronifer on this problem, I thought dangling commas were good practice).
Here are my thoughts on why these end-trailing commas are beneficial:
- Some argue that such a miniscule change won’t affect readability and instead simply adds extra stuff, but I think that it makes code more symmetrical and pleasant on the eyes (all lines will have the same format).
- Easy extendability: if one needs to add one more entry, this will prevent them from forgetting to add a comma before newlining.
- There are multiple articles on the Internet giving even more reasons, such as easy copy-paste code manipulation.
Screenshots
battleship.py, multiline data structure, dangling comma battleship.py, function parameters, no dangling comma scarymovie.py, multiline data structure, no dangling comma scarymovie.py, function call, no dangling comma _internal_eval.py, multiline data structure, dangling comma _internal_eval.py, function call, no dangling comma
You get the idea; it’s everywhere. Note that the use of NO dangling comma is more popular… however my thoughts still stand.
Possible Solutions
Vote and choose on one way: either delete all dangling commas or add them to ones without dangling commas. IMO it would also be a good idea to enforce the result - either delete or add - in the lint, and add it to our style guide.
Would you like to implement a fix?
- I’d like to implement the bug fix
- Anyone can implement the bug fix
Issue Analytics
- State:
- Created 2 years ago
- Comments:10 (10 by maintainers)
Top GitHub Comments
So there shouldn’t need to be a discussion about this nor should we have to go back and update our codebase. Dangling commas should be the standard, see PEP8. It also ensures the git blame is accurate if someone adds another option to an already existing list.
Our style guideline falls back to PEP8 for this, so there really isn’t a need for a discussion about this.
@jb3 alright. Thank you for explaining this, I didn’t realize that this kind of refactoring can arise conflicts.