-
Notifications
You must be signed in to change notification settings - Fork 873
Description
Overall I really like toml and its syntax feels very obvious to me for the most part. The only thing that doesn't is the expclicit cripling of inline tables, i.e. inline tables cannot have newlines or trailing commas. I've read the reasoning behind this in the existing issue and PR. However, I don't think that the reason given (discouraging people from using big inline tables instead of sections) weighs up against the downsides. That's why I would like to open up a discussion about this.
There's three main downsides I see:
- It's unexpected for most people using the language. Most popular languages that have
{}
style mappings allow newlines in them (JSON, Python, Javascript, Go). Also newlines and trailing commas are allowed in lists in the toml spec, so it is inconsistent in this regard. - To me even small inline tables are much more readable at first glance when split over multiple lines:
# Single line
person = { name = "Tom", geography = { lat = 1.0, lon = 2.0 } }
# Multi line
person = {
name = "Tom",
geography = {
lat = 1.0,
lon = 2.0,
},
}
- A deeply nested list of tables are forced to have a lot of repeated keys in the section headers. Compare this version with list of tables:
[main_app.general_settings.logging]
log-lib = "logrus"
[[main_app.general_settings.logging.handlers]]
name = "default"
output = "stdout"
level = "info"
[[main_app.general_settings.logging.handlers]]
name = "stderr"
output = "stderr"
level = "error"
[[main_app.general_settings.logging.handlers]]
name = "access"
output = "/var/log/access.log"
level = "info"
To the one with inline tables with newlines:
[main_app.general_settings.logging]
log-lib = "logrus"
handlers = [
{
name = "default",
output = "stdout",
level = "info",
}, {
name = "stderr",
output = "stderr",
level = "error",
}, {
name = "access",
output = "/var/log/access.log",
level = "info",
},
]
Finally, extending current toml parsers to support this is usually really easy, so that also shouldn't be an argument against it. I changed the the https://github.com/pelletier/go-toml implementation to support newlines in tables and I only had to change 5 lines to do it (3 of which I simply had to delete).