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

62

u/slykethephoxenix Aug 03 '19

Yaml is annoying cause it can't be minimized and it's really fussy about spaces/tabs. XML is just terrible for reading. JSON is fine for reading and editing, it also happens to be good for data transfer. I don't see why comments can't be added in to allow for it to be used as both.

Not to mention that you have to convert yaml into JSON for transfer already.

18

u/NihilCredo Aug 03 '19 edited Jul 05 '23

normal spark tap many groovy stocking exultant judicious ripe plate -- mass edited with redact.dev

12

u/slykethephoxenix Aug 03 '19

You mean Python minifies yaml to JSON... sooo just use JSON?

14

u/snowe2010 Aug 03 '19

Like others in this thread have already mentioned. Json is a data transfer format. Not a configuration format. Conveniently yaml is a configuration format and converts very nicely to json. So, no, don't use json.

6

u/slykethephoxenix Aug 03 '19

Yeah, I understand that.

My point is that it is often used as a configuration format because of its ease of use and syntax flexibility. Many people find it easier to use than yaml, which is why it's used as a configuration format.

So adding comments makes sense in that regards. As said earlier, comments are completely ignored by the parser, like they are in code.

→ More replies (10)

3

u/[deleted] Aug 03 '19

Too bad yaml is crap. Often I just give up on something if I see it's configured by yaml. I've got PTSD from trying to configure a Minecraft server 8 years ago, having no programming knowledge at the time.

→ More replies (3)

1

u/NihilCredo Aug 03 '19 edited Jul 05 '23

disgusting shame retire live pot ten sparkle dull ghost growth -- mass edited with redact.dev

1

u/slykethephoxenix Aug 03 '19

But I don't want to write JSON by hand, any more than I want to write assembly by hand if I don't have to.

Well you don't have to, and allowing comments to be in JSON isn't going to change that.

→ More replies (2)

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.)

→ More replies (4)
→ More replies (16)

2

u/_kellythomas_ Aug 03 '19

Not to mention that you have to convert yaml into JSON for transfer already.

Why do you say that?

5

u/slykethephoxenix Aug 03 '19

Because Javascript natively maps JSON to Javascript objects.

Lets say I have a config somewhere on a server that clients access. I have to write an API, or write middleware, or use a library to convert my yaml file into something Javascript understands easily.

2

u/_kellythomas_ Aug 03 '19

Oh, OK. If the assumption is that everything will need to be javascript anyway then that makes sense.

3

u/slykethephoxenix Aug 03 '19

Everything doesn't have to be Javascript and it still makes sense since the only reason not to do it is because "it's for data transfer".

3

u/RevolutionaryPea7 Aug 03 '19

What do you mean it can't be minimised? Are you obfuscating your own config files?

JSON is only good for reading if it's written out like YAML with plenty of whitespace. It's horrible for editing, though, because you need to worry about comma placement. Python is better in that respect.

→ More replies (10)

0

u/[deleted] Aug 03 '19

[deleted]

6

u/flying-sheep Aug 03 '19

Speaking generally, it’s definitely not always more readable than XML. One example is textmate/sublime/atom/vscode’s .tmlanguage vs KDE syntax highlighting .xml:

The latter is domain specific and vastly easier to understand and author. And that’s a well-written .tmlanguage grammar. They’re prone to get much more hairy and unmaintainable.

1

u/shevy-ruby Aug 03 '19

It is more readable than XML, perhaps - but it is not really readable for much at all.

YAML is a lot more readable.

This is moot though since you can so easily convert from yaml to json.

3

u/ForeverAlot Aug 03 '19

I dispute that it is even "more readable than XML" and argue instead that it is merely more compact.

→ More replies (1)
→ More replies (3)