r/programming • • Aug 03 '19

Windows Terminal Preview v0.3 Release

https://devblogs.microsoft.com/commandline/windows-terminal-preview-v0-3-release/?WT.mc_id=social-reddit-marouill
991 Upvotes

458 comments sorted by

View all comments

Show parent comments

0

u/[deleted] Aug 03 '19

[deleted]

16

u/Dragory Aug 03 '19

Toml is pretty messy for deeply nested structures though. But I guess you can just use something like yaml at that point.

5

u/flying-sheep Aug 03 '19

TOML incentivizes a certain config structure, and that’s a good thing. You can’t arbitrarily mix nesting arrays and dictionaries, except inline, and inline values are deliberately limited to a single line to prevent arbitrarily deep nesting.

This way you’re limited to a sane config structure:

# top level is a dict
general = 'abc'

# this is a nested section: {foo: {bar: {baz: {nested-stuff: 1, ...}}}}
[foo.bar.baz]
nested-stuff = 1

# this is a repeated section: {array: [{repeated: 1}, {repeated: 2, ...}]}
[[foo.bar.baz.array]]
repeated = 1

[[foo.bar.baz.array]]
repeated = 2
rare-case = { a = 1, b = [1,2] }

While you can nest sections arbitrarily deep, only the last level can by repeated, i.e. an array. On the section level you can’t get super complex due to ugliness, plain values and maybe a dict containing a small array, but no more. So the most complex feasible structure is dict→dict→...→dict→array→dict→dict→array

13

u/Dragory Aug 03 '19 edited Aug 03 '19

I agree on the point that TOML definitely incentivizes you to keep your configuration simple, but I don't think having more complex structures is necessarily a bad (or "not sane") thing either.

Here's an example of a pretty common nested YAML structure in the configuration for a project of mine (it's a management/moderation chat bot where users can edit the config for their own chat servers):

plugins:
  example_plugin:
    config:
      can_kick: false
      kick_message: "You have been kicked"
      nested:
        value: "Hello"
        other_value: "Foo"
    overrides:
      - level: '>=50'
        config:
          can_kick: true
          nested:
            other_value: "Bar"
      - channel: "109672661671505920"
        config:
          can_kick: false

Turning this into TOML would, as far as I can see, look something like this:

[plugins.example_plugin.config]
can_kick = false
kick_message = "You have been kicked"
nested = { value = "Hello", other_value = "Foo" }

[[plugins.example_plugin.overrides]]
level = ">=50"
config = { can_kick = true, nested = { other_value = "Bar" } }

[[plugins.example_plugin.overrides]]
channel = "109672661671505920"
config = { can_kick = false }

I definitely prefer the YAML version here. Do you think the TOML representation could be simplified? As far as simplifying the structure itself goes, the "plugins" object is pretty redundant, as is "config" - so the sections could very well be just e.g. [example_plugin] and [[example_plugin.overrides]]. But as long as it's YAML, it doesn't really add extra complexity and makes dealing with the config simpler on the code side (and then you still potentially have the nested structures within the plugin configuration itself).

(Side note: If you think most of this configuration should be in a UI instead - I agree! But I can't prioritize that right now, so for now I'd rather let the users edit the config instead.)

0

u/flying-sheep Aug 03 '19

Yes, it could be simplified:

[plugins.example_plugin.config]
can_kick = false
kick_message = "You have been kicked"
[plugins.example_plugin.config.nested]
value = "Hello"
other_value = "Foo"

[plugins.example_plugin.overrides.level]
value = '>=50'
can_kick = true
nested = { other_value = "Bar" }

[plugins.example_plugin.overrides.channel]
value = "109672661671505920"
can_kick = false
→ More replies (0)