358 points · by wheresvic1 · 8y ago · 195 comments
TOML is especially well suited for projects that need a simple configuration file that maps unambiguously to a hash table. There are still some weaknesses in TOML that make it non-optimal for large, complex config, but I'm hoping to address that in a later version of the spec (perhaps 2.0).
Happy to answer any questions you all have about TOML!
It is apparently possible to include, and then remove them before usage apparently but I've never tried.
[0]: https://plus.google.com/+DouglasCrockfordEsq/posts/RK8qyGVaG...
Using JSMin would have been a much better idea. At this point though the only downside is that I haven't yet done this for saving JSON. It's a harder problem but I don't see why it wouldn't also be doable.
edit: Apparently this library allows you to have comments, and will even preserve them when saving the JSON file.
Really? I had kind of the inverse reaction to it. Indeed useful, but definitely not understandable
In php:
$a[] = 1;
$a[] = 2;
# $a == array(1, 2)
In URIs: http://example.org/?a[]=1&b[]=2
Compare to TOML [[a]]
item = 1
[[a]]
item = 2A nice config parser will error out or at least warn loudly when encountering an unknown parameter. This helps prevent typos.
Config files should absolutely not have or need comments. If you need them directly in the config file, something is wrong. Applications should document their default settings in a different way, preferably in a README or generated documentation that also explains how to use environment variables to override the defaults. That sort of separate companion doc is the right place for notes about defaults or "why" certain config values exist in the file. The same is true for using JSON to store parameter files, etc. It's actually quite important to keep metadata about the config / params / etc. specifically out of those files, so that they are absolutely nothing but value files. Information about why a file contains those values belongs elsewhere, and it's an anti-pattern IMO to rely on comments in the config / param file.
Config absolutely needs comments. Context is everything. Comments allow me to explain to other humans why the config is the way it is. Dumping that out to a separate file is begging for it to fall out of sync when there's no comment instructing anyone to go and update the other file. Plus that's just kind of silly.
> It's actually quite important to keep metadata about the config / params / etc. specifically out of those files, so that they are absolutely nothing but value files. Information about why a file contains those values belongs elsewhere
Okay, I'll bite: Why? In every area of programming, we learn that mental context changes are harmful. We learn to avoid gotos, not abuse exceptions, add meaningful comments, and seperate concerns all in large part so when we look at a file, we can understand what's going on without referencing other files.
Now you say "oh, unless there are some config values in that file, then it's important for it to be as cryptic as possible!" Surely you see why that sounds a bit odd? Should we also base64 encode the file? Do you also hate descriptive variable names in config files?
Well, that's like your opinion, man.
If I have something set to some value in my configuration, I want those reading the configuration file (not parsing it, reading it in a text editor, e.g. to make an edit) to know why it's so.
>Applications should document their default settings in a different way
Comments in configuration files are not there to explain default settings, but to document why a setting (default or not, but usually already edit to suit your specific environment) has the value you set it to.
>Information about why a file contains those values belongs elsewhere, and it's an anti-pattern IMO to rely on comments in the config / param file.
That's a statement, not an argument. Why does it "belong elsewhere"? So that you have an extra layer, that few will bother to check?
I guess this is right if config files are only machine read and written. When I am prototyping, config auto-gen tends to come pretty late in the project (for me), and I like being able to comment things.
I also like types and time-date parameters (which JSON doesn't provide unambiguously), so by the time I've done, I've reinvented YAML+, and that's a mess, so I actually appreciate TOML quite a bit... (At the very least - I get to be a retard[0] about config later in the process)
[0] To the inevitable person that's going to call me an able-ist for using the term, I'm using the term in a self-denigrating way, ...
I just wanted to say thank you real quick.
We use TOML in [Habitat](https://github.com/habitat-sh/habitat) to define default and overridable configuration. It's super easy and expressive.
The [Habitat Core Plans](https://github.com/habitat-sh/core-plans) have quite a few examples about how it gets used in the project. If you are looking for examples of larger configuration files with .toml, then that might be a good place to look for some real world use.
Thank you again!
https://github.com/habitat-sh/habitat/blob/master/components...
What are the limitations for large complex configs, and do you think there's currently a better configuration format for them? Feel free to link elsewhere if there's a canonical location for this discussion.
That said, the alternative right now in other formats is basically a { bunch { of { braces } } which is also not the most amazing thing for long nested tables.
Good to know this is recognized. Looking forward to a better syntax to an indeed difficult problem
e.g. CSVs handle 2D tables reasonably efficiently, since you just specify values:
field_a, field_b, field_c
1, 2, 3
3, 4, 5
but I imagine TOML would benefit from something that lets you define nested tables without re-defining the table every time... which probably conflicts with the "obvious" goal. Hmm.1. Would a file path type make any sense to add? TOML is ideal for configurations, and so many configuration options use file paths. I know there are questions about platform dependency, and I don't have all the right answers for how that would work, but I could see it being possible somehow?
2. Data versioning is a big deal to me. For now there's always an option of just adding a "version" key and updating it, but can you think of a better way to do that with TOML?
I'm always overly critical of JSON (despite overall being a fan) because it doesn't specify bit sizes of numbers. I notice that TOML has specified 64 bit numbers. It's nice to see that.
2. This is still a big question, and we've been having a robust argument about it on GitHub [1]. It's a problem that so far has evaded an elegant solution, but usually when that's the case, it just means we haven't been creative enough about it yet! Or did you mean versioning of the data IN the config file? Can you elaborate?
2. So basically, the majority of people don't want to type version numbers (I see where they are coming from, but respectfully disagree). I'm not sure if there exists a solution in that case. As for my comment, I was really talking about both kinds of versioning. Mainly that, if my data is version 2.3.1, I'd expect that to also lock the version of TOML, requiring a new version of my data for bumps to the underlying data structure. Again syntax is the hard part, as I'm having trouble imagining a way to actually do this. Furthermore I've seen data formats in the past that let you version "parts" of a format, I personally like this, but don't think it's a good fit for TOML.
1. Extensible, custom types
2. Streamy, efficient, compressed and fast, leverages platform's existing native/optimized JSON parsers
3. Wide platform reach
4. Made by Rich Hickey
Just a curious thought:
Sometimes it’s handy to have a text file for small bits of numerical data. Would it be possible to extend TOML to have a “csv” section (array of arrays)?
[x,y,z]
1,2,3
4,5,6
7,8,9
Or perhaps it’d have to be: [data: x,y,z]
1,2,3
4,5,6
7,8,9It's a horrible joke and I've yet to actually use it, but it makes me happy :)
May be the config shouldn't be large and complex in the first place?
My biggest question is, why hasn't TOML used much more widely or becoming de facto standard? Am I missing something obvious?
As for adoption, it takes a long time for something like TOML to be adopted. Inertia is powerful in the development space. I also haven't had as much time as I would like to push TOML forward and evangelize it. My hope is that at some point there will be a tipping point and you'll see most projects start with a TOML config and only change to something else when TOML can't meet the project's needs.
https://github.com/perlbot/App-EvalServerAdvanced/blob/maste...
The rest of the sandbox is configured with TOML however. Just seccomp rules that I haven't figured out the perfect way yet.
See the relevant part of the spec here: https://github.com/toml-lang/toml#user-content-array-of-tabl...
(Folks downvoting, PLEASE JUST LET PEOPLE HAVE JOKES EVERY NOW AND THEN)
If you think that your brand of funny is worth braving people's disapproval, do it knowing what the reaction is going to be. If you don't like people disapproving, then go elsewhere, or engage here in a way that people prefer.
Over the many years of the usage of INI I think occasionally we've seen developers add their own touches to how they support types, sections, groups, multi-dimensional arrays or other structures within config files that certainly indicated a need for some more standardized advancement here.
I really hope this gains a lot of traction, because there are so many scenarios where things like XML or JSON are forced into roles they really don't belong in.
One thing that I would say is that it might be worth indicating a standard header that can be used at the very least in cases when it is not stored in a file with a .toml extension. It would not surprise me at all to see TOML widely used with extensions that describe better the intent of the file rather than the format.
I have been working on a TOML reader/writer for golang that supports read/change/write and format (like go fmt) that sometime I will get enough time to actually finish and release. =)
According to the repo history, it did... 5 years ago, until someone noticed and corrected it.
In my opinion, one of the more useful features was the addition of Joda-style datetimes [2][3][4][5], which disambiguates between various kinds of datetime constructs aren't interchangeable yet commonly conflated. It's fair criticism that the addition of rich datetime types exceeds the language's original 'minimal' goal, but too many other languages and formats these days just punt to RFC3339 and leave no guidance or tooling on how to represent dateless times or timeless dates without introducing a ton of side-effects. This is a place where language standard libs, with few exceptions, have repeatedly dropped the ball, and similarly, language or library-agnostic, generic guidance is nowhere to be found.
TOML raises the bar here, by providing a concept and notation to specify these values at rest, and gives parser writers, as opposed to the users, the task of finding a way to represent these values in whatever way is idiomatic for the given language.
[1] https://github.com/toml-lang/toml/blob/master/CHANGELOG.md [2] https://github.com/toml-lang/toml/pull/414 [3] https://github.com/toml-lang/toml/pull/362 [4] https://github.com/toml-lang/toml/issues/412 [5] https://github.com/toml-lang/toml/issues/263
For some reason, though, I just struggle with the syntax. It says it's "obvious" but it wasn't to me. I think it says something that the README is full of "this TOML would be represented like this JSON", to help you understand what's going on. Every time I saw that, I was like "oh, now I get it." I don't know if that means JSON is just inherently more understandable, or I'm just more used to it, though.
Are there obvious downsides to JSON for config that I'm missing? What are the advantages of TOML over JSON? Maybe eventually it'll "click", though.
I think the following mean the same thing:
[[foo]]
bar = {baz = 5}
[[foo.bar]]
baz = 5
But I don't think the following works: [[foo]]
[[bar]]
baz = 5
That is, I think the double bracket syntax always starts at the top level? While the `=` are relative to the double brackets above it? Something about all that is non-obvious to me, and I don't love that there's multiple ways to do the same thing.for me, there are two. firstly, TOML supports comments.
secondly, TOML or INI is very readable without indentation. i have learned that removing indentation from configuration files makes non-technical people much more comfortable editing the file by hand. when many non-technical people see braces and indentation, they feel overwhelmed and associate it with complexity.
i don't really use TOML's more advanced features, though. i basically just use it like INI.
(Well, I guess there's not that much to win/lose in the area of config languages, but still) (Also, I think it works pretty well, so this is not to downplay TOML!)
I think the moral of the story is: just put your whacky ideas out there and see what happens. You never know when you'll hit a chord.
Pip's choice was made for them in the form of PEP 518 [2]. The authors of PEP 518 explain their rationale [2][3], which largely boils down to XML being too wordy and awkward to hand-edit, JSON awkward to hand-edit, various formats used by existing python tooling were underspecified and implementation-dependent, and YAML's python parsers being fairly complex and hard to vendor.
[1] https://news.ycombinator.com/item?id=7938388 [2] https://www.python.org/dev/peps/pep-0518/ [3] https://www.python.org/dev/peps/pep-0518/#other-file-formats
Basically, I wanted something that was (1) simple, (2) terse, (3) supported comments, and (4) supported recursive data structures. Requirement (1) eliminated YAML, requirement (2) eliminated XML, requirement (3) eliminated JSON, and requirement (4) eliminated INI. Of the remaining formats, TOML seemed to be the most popular and had the most traction, so I went with that.
It feels like Scala (Lightbend is the company behind Scala) in the sense that there are 100 ways to achieve the same thing and having different levels of "code elegance", but for me it's a plus, since I'm a Scala fan.
# THIS IS INVALID
a.b = 1
a.b.c = 2
Why? I'm sure there is very good reasoning - but it makes me have to reason about my data in a manner I consider backwards/confusing. name.first = "Bob"
name.last = "Smith"
# Can't do this because name.first has already been defined
# name.first.alternative = "Robert"
# This is too ambiguous
name.alternative = "Robert"
# And this is backwards to me
name.alternative.first = "Robert"
Some people might suggest to instead do first.name = "Bob"
last.name = "Smith"
alternative.first.name = "Robert"
But now nothing is scoped to [name] and if I need to get the full name I can't just pull in [name] but need to pull in [first], [last], and [alternative]. That's really messy in my opinion. All of these are names and should be scoped to [name] and not their own structure.Because it avoids these problems, your "name.alternative.first" example seems perfectly sensible to me. Alternatively, the name might be an array:
[[name]]
first = "Bob"
last = "Smith
[[name]]
first = "Robert"
It's probably best to think of TOML as convenient syntax for creating a JSON-like structure. What kind of JSON would you expect as the result of your config examples?Your explanation is perfect and I understand the justification why it isn't possible now - so thanks for that! The array alternative provided by xinau is also an acceptable replacement - maybe even better to be honest, especially in this particular scenario.
>It's probably best to think of TOML as convenient syntax for creating a JSON-like structure. What kind of JSON would you expect as the result of your config examples?
I came back from lunch and realized what I was trying to do didn't make sense while trying to convert it to JSON. Having name.first be both a value and contain an object doesn't make sense - unless it were to contain an array value but then why have the object and not just have the value? All very silly. So I guess my "only issue with TOML" is that I never sat down and tried to express what I wanted to express in any other way. It made a lot more sense in my head than on paper. :)
One key can't have multiple values with different types. For example in json:
{ "name" :
{ "first" : "Bob",
"last" : "Smith"
}
}
How would you add a "alternative" key to the "first" value type. The only way i can think of is something like this. { "name" :
{ "first" : "Bob",
"first.alternative": "Robert",
"last" : "Smith"
}
}
or as @latk suggested, let "first" be an array, with it's first entry being the non alternatives. { "name" :
{ "first" : ["Bob", "Robert"],
"last" : "Smith"
}
}
I think this is by design. To quote @mojombo "simple configuration file that maps unambiguously to a hash table".But this is only a guess.
I've been trying to push RON as an alternative, and it works very well for WebRender, Amethyst, and other projects in Rust.
For the projects I've used TOML on, it was a nice breath of fresh air and a terrific improvement over JSON (still mad about JSON's lack of comments). Simplicity wins!
Homogeneous arrays can come in the following forms
- Shallow, literal type (a list of lists, regardless of the nested lists contain)
- Full, literal type (a list of dicts of strings)
- Logical type
There are many times where a list is the best type for my data but I want to take advantage of logical types for easier configuration by my users.
Below is an example of what I mean by "homogeneous logical types":
`Cargo.toml` has you specify dependencies using a dict
[dependencies]
foo = { "version" = "1.0" }
but allows a short-cut syntax where a string value is assumed to be the version value in the above dict. [dependencies]
foo = "1.0"
Generally this is done in Rust using Enums enum Dependency {
Version(String),
Specification(HashMap<String, String>),
}I'm not sure I understand your complaint, though, can you give me another example of how it's biting you in real life?
Except the name would be duplicated with the content I'm storing.
As for an example, its effectively Cargo. My use case is very similar (dependency reporting) but my content is slightly different (as I said, the value would effectively duplicate the key)
list = [
"1.0",
"2.7",
{ version = "1.4", path = "..." },
"9.9",
]
Is that correct?https://arp242.net/weblog/yaml_probably_not_so_great_after_a...
I think the big problem is that YAML is dynamically typed. If I had schema-enforced config files, I'd be perfectly happy to say that for boolean typed data all the values of YES and NO and ON and OFF and T and F and 0 and 1 can all be reasonably interpreted as a Boolean True and False. The problem happens when a string-typed or integer-typed member can also have their ON value interpreted into Boolean TRUE.
Probably because they are the only two features that need delimiters at start and end. The rest are only one-liners or simply stop if the next of the same type starts.
Enter TOML: I can paste a bunch of "var_x = 2"-type statements (there's like 50) directly from Python, read them as a dictionary and find-replace all appearances in like 5 minutes while I'm waiting for an Uber.
Thanks Tom!
Stylistically, I agree with you as TOML is clean and well thought. Moreover, TOML has support for more data types that JSON lacks leading to ugly workarounds (floats as strings anyone?). The main advantage of JSON is that its encoding/decoding is included in JS as it is, and it's generally deeply ingrained in the Node community.
Of course nothing is impossible, but I think that the ship has sailed. I was just dreaming of what could have been :-) Subtle details in NPM's behavior would've probably been designed differently if it was necessary to make updates to the package file without destroying layout and context.
[[designers]]
name = Guido
lang = Python
[[designers]]
name = Larry
lang = PerlThat all said, for flatter schema's I do personally think TOML is more readable than it's JSON, YAML and XML counterparts. If there is one thing I did like about Windows back when I used to run it, it was the syntax of INI files (which TOML was heavily influenced by).
Ultimately though, there is no perfect solution for all problems.
Yes. But for nested data, I find TOML becomes the least readable and I have to fall back to YAML or JSON.
Maybe we need just one more ML...
Still there FWIW.
For the most part the language seems like a smarter slightly more flexible INI which I like (although there's no real standard for INI, most formats don't allow for nested arrays or tables,) but why embrace bracket notation for arrays, but not a keyed syntax with the same brackets for tables?
Something like this would have been be a lot cleaner to me:
[designers]
[name = Guido, lang = Python]
[name = Larry, lang = Perl]"YAML Ain't Markup Language"
It works great based on my small amount of testing, and TOML is awesome! I wish more people start using it.
- Is interpolation supported? e.g. "key1" = "value" and then "key2" = "$key1". That would be very useful in avoiding repetition.
- What is the keyword for null? e.g. when I want to set the value to null
No, there is no facility for variable templating, interpolation, references, or anything of the like in toml.
If you wanted that, you could implement it in your application by doing post-processing on strings, or you could not use TOML.
> What is the keyword for null?
If you have "x = 1", you can always comment it out with "# x = 1". There's no specific support for null.
it would be kinda silly to have it anyways since null is a language construct more than anything else, and e.g. some lanuages support mixed strings + nulls in one array, but many don't.
https://github.com/lantiga/clj-toml/blob/0.4.0-instaparse/sr...
What a lovely language! I may have to use it..
> Newline means LF (0x0A) or CRLF (0x0D0A).
Complicating things from the start. Not a good sign.
A language for configs is different from a data interchange language: the former is intended to be written and edited by humans.
See https://arp242.net/weblog/json_as_configuration_files-_pleas...
And you can't expect windows users to always check their editor is lf compliant. Toml is not just for programmers
Changelog: https://github.com/toml-lang/toml/blob/master/CHANGELOG.md#0...
They're incredibly useful if you need to specify an exact floating point value, and about rounding or precision issues.
Other languages than perl support them, but that article does a good job of demoing them
https://github.com/adambard/learnxinyminutes-docs/issues/315...
In any case I'm glad to see it in several open source projects (Mailtrain for example). It's so much easier to read for humans than JSON.