-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow trailing commas in multi-line [] and {}. #28
Conversation
Having trailing commas in multi-line arrays and hashs makes diffs only touch the lines that are related, and makes editing in general much more consistent. We should still not use trailing commas in single line literals, even if rubocop now allows it. This rule in Rubocop makes very little sense, and is mostly based on being consistent with [1,2,3] not being written [1,2,3,]. AFAIK, there is no way to tell Rubocop to allow trailing commas in multi-line literals, without also enabling it for single line literals. I'm pretty sure there is an issue open about this in the rubocop repo on GH, but it was clear most people with power didn't care, or want to change it.
@kelvinma do you have a reason you don't like this? |
Comma implies that there is something following. |
While I agree with that, I personally feel like the practical benefit of using them outweighs the natural language grammar. It's nice to have every line be consistent. [
1,
2,
3,
] vs. [
1,
2,
3
] Here the |
I should listen to myself rubocop/ruby-style-guide#273 (comment) |
Practical Comments That said, I think the change you made here would just disable the check that flags trailing commas, rather than enforcing them.
In a perfect world I think we would go with number 2, but that doesn't seem practical right now without the level of autoformatting we have in Elixir. Academic Comments (Just for fun) I could also go all and disagree with Nate's comment that
The first and second elements are represented by a cons type where the address register is a number and the decrement register is a reference to another cons pair. |
@zcotter It will be coming soon to elixir formatter. The core team is just waiting on formatter getting more mileage as it has only been in production since 1.6 |
TLDR: I'm happy with both, as they both have their merits. This is a case where there really isn't a correct answer. I'm clearly torn between these two styles. I'm more than happy with either at this point. The practical pros can be seen as the following: Trailing Commas:
No Trailing Commas:
@zcotter your argument about LISP is off. The fact that the underlying data structure is a recursive definition and uses a marker like P.S. I think my opinion has changed a bit on this since 2014 because I've since spent a lot of time writing macros in Racket and Rust. When you think about macros, you start thinking about sytactic consistency over semantic correctness in many cases. |
Since conversation has fizzled, I'm closing this issue. Current style stands. Feel free to reopen if you'd like to push for a change harder. I'm easily swayed. |
Having trailing commas in multi-line arrays and hashs makes diffs only
touch the lines that are related, and makes editing in general much more
consistent. We should still not use trailing commas in single line
literals, even if rubocop now allows it.
This rule in Rubocop makes very little sense, and is mostly based on
being consistent with [1,2,3] not being written [1,2,3,]. AFAIK, there
is no way to tell Rubocop to allow trailing commas in multi-line
literals, without also enabling it for single line literals. I'm pretty
sure there is an issue open about this in the rubocop repo on GH, but it
was clear most people with power didn't care, or want to change it.