4 ms·
TOML remains severely underrated, for some reason. It's easy to read, easy to write, trivial to map onto JSON, and refreshingly clear of footguns. There are co
by samatman 6y ago
TOML remains severely underrated, for some reason.
It's easy to read, easy to write, trivial to map onto JSON, and refreshingly clear of footguns. There are comments!
If you get to pick your format for a configuration language, start by trying to talk yourself out of TOML. You'll probably fail; I'm interested to hear if folks out there have examples of something TOML is bad at, because I didn't come up with any when I was doing this evaluation for my own project.
- baq 6y agoIt’s a bit too strict for configuration files and too verbose for an interchange format. It’s an improvement over JSON and arguably yaml but it won’t beat actual syntax.
- ben509 6y agoAnother comment brought up StrictYAML, and they have a good dissection of the problems with TOML[1]. Personally, after doing a few pyproject.toml files, I still find it confusing and awkward as soon as you get past simple headers and key-values. TOML is like YAML, it translates to "jsonic" types, but JSON's virtue is that simple 1:1 mapping between syntax and data. TOML and YAML both have non-obvious syntax and there's a layer of translation you have to do to understand what you're actually generating. But I don't really want to generate a big blob of objects, arrays and such, I want to configure something. I think that's why none of these languages work very well. [1]: https://hitchdev.com/strictyaml/why-not/toml/ https://hitchdev.com/strictyaml/why-not/toml/
- saghm 6y agoIMHO the arguments in your link aren't particularly convincing. The three main points seem to be verbosity (defined in terms of total number of characters for a given file, which is not nearly as important to me as readability), not having indentation be significant (which might be downside to a Python programmer but feels like a win to me), and having explicit syntax to distinguish between types (e.g. strings being quoted, which is preferable to me, since it makes them stand out as values compared to the keys). If these are the strongest arguments against TOML, I find myself fairly convinced that TOML is probably the format I'd like to use most even though I was I different towards it before clicking the link.
- throwaway894345 6y agoI would be very interested in an experiment in which participants are required to write Kubernetes manifests in YAML or TOML, and what the analysis suggests they prefer (after controlling for the right set of variables). I don’t like YAML, but TOML stops being nice very quickly as the size or complexity of the data increases IMO.
- afiori 6y agoThe second point is not about whitespace, but rather about how you can write your document out of order. specifically TOML supports a syntax that allows to write documents like: (not actual syntax) a.b=1 a.c=2 d=3 a.e =4 that would translate to {a:{b:1,c:2,e:4},d:3}. So the criticism is that (in various cases) you need to read the entire document to be sure to have fully parsed one subtree of the document.
- samatman 6y agoThat's not a bad argument against using TOML, and I'm inclined to agree that TOML is more verbose than it has to be for heavily-nested maps-of-maps-of-maps. Which you can pretend is a strength, since I consider doing that an anti-pattern. But it is a valid critique. However, the TOML they offer as a comparison to the StrictYAML is probably auto-generated (they do say "serialized TOML equivalent") and it's quite a bit noisier than it has to be. TOML deliberately has a couple of ways of writing arrays, and a one-line short format for maps: you're supposed to alternate these, and this technique could eliminate most of the repetition in that particular file. I still wouldn't choose TOML for a complex tree of user stories where the keys are all long strings of English: that's an example of the kind of thing where you might talk yourself out of using it! Here's the counterpoint I want to offer: stories of YAML "configuration languages" escaping confinement and becoming headache-inducing repositories of monstrous complexity are practically cliche at this point. Part of why that is, is that you don't pay for that complexity "up front": It's just a nice list! It's easy to read! I would add one thing to TOML if I could: it should default to a string for the value part of a key-value pair, if it can't make anything else. So my_val = 42 Makes a number, my_string = "42" Gives you a string, and my_regex = ^\"(\\.|[^\"])*\" lets you handle regexes without the obnoxious double-quoting problem, while removing a lot of the verbosity and ceremony from the format.
- andreareina 6y ago> TOML deliberately has a couple of ways of writing arrays, and a one-line short format for maps: you're supposed to alternate these, and this technique could eliminate most of the repetition in that particular file. Could you provide an example of what you mean, or point to some such? We're having a spot of trouble with arrays of maps ourselves.
- samatman 6y agoIf you look at https://github.com/toml-lang/toml/blob/master/toml.md https://github.com/toml-lang/toml/blob/master/toml.md, you'll see "Array", "Inline Table", and "Array of Tables", and you can put an inline table inside an array. This breaks down when things get really branchy. TOML really expects keys to be symbols rather than strings.
- smitty1e 6y agoIn the future, everyone will write a markup language that will be the flavor of the quarter-hour, begetting a cottage industry of translation tools.
- faitswulff 6y agoActually, there are quite a few instances of that happening, many of which are listed here: https://wiki.alopex.li/BetterThanJson https://wiki.alopex.li/BetterThanJson
- Arnavion 6y agoI like TOML too, but speaking of footguns, there is one where it comes to serialization. If you have something like: struct Foo { int bar; Baz baz; int quux; } ... you can't naively serialize this like: [foo] bar = 5 [foo.baz] ... quux = 6 because that makes `quux` a property of `foo.baz`, not of `foo`. The serializer has to be smart enough to recognize that primitive fields have to be serialized before object fields. As a practical example, Rust's TOML library is not smart enough to do so, though it does at least detect when this would happen and fails with a runtime error. (The workaround is to change your type definition to reorder the fields yourself.) Ref: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=dbc26ca3f9ba00c0d30492ae73e3a230 https://play.rust-lang.org/?version=stable&mode=debug&editio...
- hombre_fatal 6y agoYeah, I never liked how in TOML once you start a [table], you can never go back to the top level, just start more [tables]. What it means in practice is that if you want to use [table] syntax because it's more readable for this one key, you have to move it to the very end, away from the keys it was related to. Wasn't impressed.
- epage 6y agoI love TOML for simple data but it starts to have problems with complex data or data in cettain workflows (I can't imagine a Gitlab or Azure Pipelines file in TOML). However, a benefit to TOML's weakness with complex data is it encourages developers to keep things simple.
- dnautics 6y agoI love toml and used it extensively, but there are definitely warts. Arrays of objects are particularly painful[0]. If you decide that a first-level singleton non-object parameter semantically belongs after a first-level object parameter, you can't do it. Which is kind of no-duh, but TOML is simple enough that you might forget that you can't do that [0] i mean this: [[abc]] param="foo" [[abc]] param="bar" [[abc]] param="baz" Edit: ok, just read the sibling comments and they totally echo my gripes. So there's something about our common issues.
- deleted 6y ago[deleted]
- inshadows 6y agoExactly what does it solve? You ditch one configuration language for another (less feature rich) one, and then do imperative programming in it anyway.
- samatman 6y agoDepends on what you're doing, right? Dhall is going to be better than writing an inner-language monster of a config language, in YAML, TOML, or JSON. Let someone else do the work, I agree. But if the goal is to have a human-editable file that loads a few values into a map, and it often is, TOML is pretty nice. I think we've all been burned by 'configuration languages' which take on the complexity of a full programming language, in a worst-of-both-worlds sort of way. But sometimes you just want to change a font, or specify tabs-or-spaces, or set a non-default remote.
- inshadows 6y agoI have never been burned by the configuration language complexity. I'm constantly being burned by its limitation. You are right that for configuration TOML is OK. But the linked article talks about YAML in context of stuff like Ansible or K8s, where usually plain and simple imperative programming is coerced in YAML syntax.