Skip to content
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

Reduce verbosity of sub tables #413

Closed
dstufft opened this issue May 12, 2016 · 5 comments
Closed

Reduce verbosity of sub tables #413

dstufft opened this issue May 12, 2016 · 5 comments

Comments

@dstufft
Copy link

dstufft commented May 12, 2016

Right now since sub tables require repeating the keys of any of it's parent tables, any situation where you want multiple sub tables, particularly nested, tends to end up being very verbose, looking something like:

[a]
value = 1

[a.b]
value = 2

[a.c]
value = 3

[a.c.d]
value = 4

[a.e]
value = 5

This I believe makes TOML uglier than it needs to be for situations where you end up with multiple nested sub tables. The problem primarily comes from the repeated key names of the parent tables, so what if TOML just allowed you to omit that? So essentially the above would become:

[a]
value = 1

[.b]
value = 2

[.c]
value = 3

[..d]
value = 4

[.e]
value = 5

The rule would be pretty simple, the . make it relative to the previously defined table with one fewer ..

While whitespace is still optional, you can make it more immediately obvious what is going on by applying some whitespace here to turn the above into something like:

[a]
value = 1

  [.b]
  value = 2

  [.c]
  value = 3

    [..d]
    value = 4

  [.e]
  value = 5
@TheElectronWill
Copy link
Contributor

I think that's a good idea :)
I'll see how to implement it in my TOML parser.

@FranklinYu
Copy link

FranklinYu commented Jun 14, 2016

Interesting, but that might lead to:

  1. "overhead" in your mind: when you see
# something before...

[..key]
value = 1

you need to look above (possibly far away) to search for [.b] and [a].
2. complexity for parser, which need to fail correctly and provide meaningful error message to input with

[.a] # invalid without top level table above

and

[a]
    [..c] # invalid without intermediate table name

Note that TOML is designed for easy parsing than functionality.

I guess the above explains the downvotes. (Note: I myself do not fully agree with the second; I just provide such a point.)

@rmunn
Copy link

rmunn commented Jul 8, 2016

While I can see the convenience for writing TOML files, I don't believe it's worth the extra parser complexity. And I realize that I say this as the person who opened #409, but there's a difference. Hex and octal have some use cases where they are essential, not just nice-to-have (Unix file permissions, for example), and the added parser complexity is small. This suggestion, though, adds a lot of complexity for (IMHO) very little gain, and I don't believe that the trade-off is worth it in this case.

@jleclanche
Copy link

jleclanche commented Aug 7, 2016

I'm currently evaluating using TOML for an ansible-like DSL which defines tasks like so (simplified):

[defaults]
user = "admin"

[[tasks]]

[[tasks.clone_repo]]
desc = "Clone repo from github"
type = "git"
[task.clone_repo.args]
source = "https://github.com..."
dest = "$HOME/repo"

This is a tough sell due to verbosity and it's the second time I encounter the use case, extremely quickly after picking up TOML which makes me think it's a pretty core issue to the language. Neither JSON nor YAML have this issue due to syntactic scoping.

Another issue caused by the verbosity is the human error element. I was going to write a paragraph about this, until I noticed upon remarshalling that the last header is missing an s. Oops - I guess this leads by example?

What this could look like:

[defaults]
user = "admin"

[[tasks]] # Would that work?

[[.clone_repo]]
desc = "Clone repo from github"
type = "git"
[..args]
source = "https://github.com..."
dest = "$HOME/repo"

Much less repetitive and removes most potential human errors.

To address @FranklinYu's concerns regarding mental overhead on read:
This argument would have no ground in a discussion about JSON/YAML (say, about an array with a lot of subvalues) and I don't see why it should be any different here. The concern here is to actually reduce write overhead, which incidentally I believe can reduce read overhead as well. In the cases where it doesn't, as this is an optional feature, it would be wise for the writer to use fully-qualified key names.

As for parser complexity, erroring properly should not be overly complicated here. What this adds to parsing is tracking the last-defined value at each level. I will expand on your example with another potential error though:

[a]
[.aa] # a.aa
[..aaa] # a.aa.aaa
[b]
[..baa]  # !!! could become a.aa.baa if not clearly specified

Conclusion: I'm strong +1 on inclusion of such syntax.

@mojombo
Copy link
Member

mojombo commented Dec 6, 2017

I've never seen a repetition-reducing syntax of this sort that I think is obvious enough to be included in TOML, including all the proposals seen here. What might solve some of these problems, though, is dotted keys as seen in #499. It's an obvious solution that would allow a reduction in repetition for certain cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants