It appears that arrays allow a final trailing comma even if not followed by a value, whereas inline tables do not. Should these commas not be consistently either allowed (if deemed a useful feature) or disallowed?
Just curious: When and how is a trailing comma considered a useful feature?
Trailing commas are very useful for multi-line data, e.g.
[
1,
2,
3,
]
If I now add a fourth value to that array, I don't have to worry about adding a comma after the third one, since it's already there. Having commas after every value also makes sorting them much easier. If no trailing comma is allowed in such situations, mistakes are much likelier; they have repeatedly happened to me and certainly also to others.
Inline tables, on the other hand, are meat to fit into a single line in any case, so that kind of reasoning does not apply. There is no really good reason to use a comma after the last value in an inline table, as far as I can see. But I agree that consistency is expected and useful as well, so it would probably be better to allow trailing commas in inline tables as well, so that people can simply memorize "TOML allows trailing commas" rather than having to worry about more complex rules.
If I now add a fourth value to that array, I don't have to worry about adding a comma after the third one, since it's already there. Having commas after every value also makes sorting them much easier. If no trailing comma is allowed in such situations, mistakes are much likelier; they have repeatedly happened to me and certainly also to others.
I'd like to add that it is also useful to avoid diff tools indicating that you modified one line and added another one (or maybe that you removed one line and added two) when you simply wanted to add one line 鈥攖he new element of the array. Also a reason to nearly always prefer multiline arrays.
@ChristianSi I would also argue that inline tables should allow newlines, just like arrays...
@ColinH I think that this discussion has already occured. Inline tables weren't allowed to spread across multiple lines because that's the purpose of normal tables. If you need multiple lines don't use inline tables.
@Hrxn Allowing the trailing comma is useful for humans. I've seen so many people failing to write a correct configuration because of one character. Why not be tolerant?
@TheElectronWill Yes, I understand, and am wondering what the rationale is, it seems to make TOML much less "obvious":
[a]
# These are all allowed:
b = [ 1, 2, 3 ]
c = [ 1,
2,
3 ]
d = { x = 1, y = 2, z = 3 }
# This is NOT allowed:
e = { x = 1,
y = 2,
z = 3 }
Usually my goal is to keep things as orthogonal and flexible as possible, and to not force a certain style on the user without good reason.
But this issue was about the commas, so we don't need to continue this other discussion, in particular since, as you say, it has already occurred, and the choice been made.
Thank you for the clarification, when the time comes I will implement TOML inline-tables as specified.
@ColinH Please search the issue tracker for the original discussion. That should answer your motivation questions. Otherwise, we don't need to re-litigate it here.
@BurntSushi Yes, as stated I didn't want to further discuss anything but commas here. Thank you for the pointer.
On that note, do you see a consensus on whether to add trailing commas to inline-tables? I don't care either way, with this issue I just wanted to point out that the current situation seemed inconsistent.
The arguments that holds for the comma in arrays also hold for inline tables, therefore it seems logical to allow it in inline tables too.
Don't get me wrong, I was not trying to express opposition to the idea in any way.
Just trying to understand, because I have not used it for myself so far, unsurprisingly, because I don't do this stuff by trade etc.
So thank you for giving me some examples, and especially @Sanva for the example how it can be beneficial for diffs.
I'd say that the status quo is fine.
For arrays, @Sanva and @ChristianSi made the relevant points.
Optional trailing commas within inline tables do not make sense, much like comments don't since they only make sense if you could break up the literal across multiple lines. TOML already has a nicer multi-line syntax for tables.
Obviously, this is at @mojombo's discretion -- the language literally has his name on it. :P
Since trailing commas are specifically designed to accommodate multi-line arrays, I don't think there's an obviousness case for them. To me, the obvious thing would be to disallow them since inline tables can only appear on a single line. On top of that, allowing something that is really only useful in a multi-line context for something that is restricted to a single line would be very much non-minimal. As such, I like things the way they are. Thanks for the discussion, everyone!
Most helpful comment
@TheElectronWill Yes, I understand, and am wondering what the rationale is, it seems to make TOML much less "obvious":
Usually my goal is to keep things as orthogonal and flexible as possible, and to not force a certain style on the user without good reason.
But this issue was about the commas, so we don't need to continue this other discussion, in particular since, as you say, it has already occurred, and the choice been made.
Thank you for the clarification, when the time comes I will implement TOML inline-tables as specified.