How about allowing an optional trailing comma appended in record? So below
coding style will be encouraged, when writing a record with many fields:
type album = {
title: str,
...<other fields>...
artist: str,
};
let x = {
title: "some",
...<other fields>...
artist: "artist",
};
To append a new field to the record, adding a line of new field is enough
instead of (1) add comma to the previous last field; (2) add new field.
Besides conveniences of editing or recording of the fields within a record, the
trailing comma helps generate clean patches. Since the order of record fields
are important, new fields are more likely to be appended to the end of the
record. It's not uncommon that this kind of merge conflict happens.
Another approach is writing the record like:
type album = {
title: str
, artist: str
};
But this looks more like an afterthought and the same issue exists if change
the first field.
ECMAScript5[1] allows trailing comma in object initializers. Python
has long been
supporting this. C structure fields deliminators are semi-colon, like Rust
tag, while C enum declaration allows trailing comma in C99[2].
Go doesn't have this issue, since each field is written in its own line and
deliminators are all eliminated.
---
1. https://bugzilla.mozilla.org/show_bug.cgi?id=508637
2. http://david.tribble.com/text/cdiffs.htm#C99-enum-decl
PS. Not sure if this is the right time of raising this kind of syntax
discussion. I read a line about avoiding syntax discussion on
Wiki presently. Sorry for breaking the rule if there is one. :)
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev