question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Inconsistency: "Dangling Comma" on multiline data structures and function calls

See original GitHub issue

Description

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:

  1. 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).
  2. Easy extendability: if one needs to add one more entry, this will prevent them from forgetting to add a comma before newlining.
  3. 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:closed
  • Created 2 years ago
  • Comments:10 (10 by maintainers)

github_iconTop GitHub Comments

2reactions
janine9vncommented, Jun 3, 2021

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.

0reactions
Objectivitixcommented, Jun 3, 2021

@jb3 alright. Thank you for explaining this, I didn’t realize that this kind of refactoring can arise conflicts.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why you should enforce Dangling Commas for Multiline ...
With the dangling comma only the new entry is visible in the diff. With the dangling comma only the new entry is visible...
Read more >
trailing commas should be encouraged in multiline literals #273
The comma is logically a separator between elements of the array/hash. Separating nothing implies subtly that there is something after the last ...
Read more >
c++ - int a[] = {1,2,}; Why is a trailing comma in an initializer-list ...
So, my rule of thumb is: use the trailing comma if the list spans multiple lines, don't use it if the list is...
Read more >
comma-dangle - ESLint - Pluggable JavaScript Linter
A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease.
Read more >
Trailing commas - JavaScript - MDN Web Docs
Trailing commas (sometimes called "final commas") can be useful when adding new elements, parameters, or properties to JavaScript code.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found