6 ms·
Bah. While YAML is far from perfect, it's fine for random config files written by humans. TOML is mostly better, but from its own homepage (https://toml.io/en/
by kstrauser 3y ago
Bah. While YAML is far from perfect, it's fine for random config files written by humans. TOML is mostly better, but from its own homepage (https://toml.io/en/ https://toml.io/en/):
[servers]
[servers.alpha]
ip = "10.0.0.1"
role = "frontend"
[servers.beta]
ip = "10.0.0.2"
role = "backend"
is ugly to my eyes. And I'd rather swallow my own tongue than have to hand-edit XML in the most common case where there's not a dedicated editor for that specific doctype.
In fact, I'd echo the linked article's argument back: I don't know of a case where XML is the best option. For human-edited files, pick almost literally anything else. For serialization, JSON handles the common cases and protobufs-and-friends are better when JSON isn't enough. There's not a situation I can imagine where I'd use XML for a greenfield project today.
- kllrnohj 3y ago> For human-edited files, pick almost literally anything else. I'd still take XML over JSON for human-edited files. At least XML supports comments. > For serialization, JSON handles the common cases Counter-point, JSON sucks and is way overused. The types are too fuzzy, the syntax too quirky, and validators/schemas are almost never present. You can bolt that all on, but it wasn't designed for it and it shows. It was designed to be eval()'d, which you should also never do because it's a terrible idea. It's flawed at the foundations.
- kstrauser 3y agoThose are valid points, and while I have a different opinion, I can't say you're wrong about any of it. But I will say that the first time I used a JSON API that had replaced an XML one, I almost wept with relief. Perhaps because JSON is so simple, it pushed APIs toward having simpler (IMO) semantics that were far easier to reason about. Concretely, I'll take an actual REST API (that is, not just JSON-over-HTTP) over the SOAP debacle any day of the week. I know you can serve XML without using SOAP, but to me they're both emblematic of the same mindset. Still, at least neither of them are EDI.
- SahAssar 3y ago> The types are too fuzzy Do you mean non-json types? Because the supported types seem pretty straightforward. (besides perhaps supporting null bytes in strings in things like postgresql) > the syntax too quirky Care to explain? This has always seemed like one of jsons strengths. The syntax for what is valid is pretty straightforward.
- kllrnohj 3y ago> Do you mean non-json types? Because the supported types seem pretty straightforward. (besides perhaps supporting null bytes in strings in things like postgresql) What is a "number"? Is it a float? int? short? double? BigDecimal? What about time values? Or dates? Oh, you have to just shove those into strings and hope both sides agree? That's fun. > Care to explain? This has always seemed like one of jsons strengths. The syntax for what is valid is pretty straightforward. One example is the json "spec" on json.org does not allow trailing commas yet many parsers do
- lmm 3y ago> Counter-point, JSON sucks and is way overused. The types are too fuzzy, the syntax too quirky, and validators/schemas are almost never present. You can bolt that all on, but it wasn't designed for it and it shows. XML's validation, schemas and typing are far more complicated and equally useless - the impedance mismatch is too big, all they do is give you a whole bunch of extra ways to shoot yourself in the foot, particularly in the presence of namespaces. If you want something fully structured, protobuf or equivalent is the way to go (and converting back and forth between protobuf and JSON is relatively painless).
- Turskarama 3y agoXML Namespaces are one of the worst anti-features I have ever encountered. I have yet to see a legitimate use for them, but they make parsing way more of a pain than it needs to be. Also the use of attributes vs nested tags seems pretty arbitrary and in my experience attributes are hardly used at all.
- jmbwell 3y agoYeah. Look, I’m a booster for XML. But I recently worked on a project to interface with Microsoft Office documents. So many conflicting namespaces. So. Many. Conflicting. Namespaces. Often for the same “kind” of document, at least as far as the user is concerned. So much flexibility. So many ways to paint yourself into a corner. Such a nightmare. Also, the reason we have jobs.
- fiddlerwoaroof 3y agoYeah, I personally find XML elegant and well-designed compared to the popular alternatives today. And things that supply what’s missing (for example, JSON-LD and JSON Schema) aren’t much less complicated than the XML equivalents. Of alternatives, I think EDN is the closest to being a satisfactory replacement because it supports namespaces.
- ChrisMarshallNY 3y agoComments are absolutely vital, in my opinion; especially for config files. I don't like XML, YAML, or JSON. If I am doing server-side PHP, my config files are executable PHP. It's my responsibility to make sure they can't break the system too much. If I am doing host-side stuff (like Swift Package Manager), I prefer executable Swift files. But I cut my teeth on BNF[0], and X.500[1]. They worked well, but were painful. They make YAML look good. [0] https://en.wikipedia.org/wiki/Backus–Naur_form https://en.wikipedia.org/wiki/Backus–Naur_form [1] https://en.wikipedia.org/wiki/X.500 https://en.wikipedia.org/wiki/X.500
- bombcar 3y agoComments that "self-document" a config file are great. Comments that result in: #Frontend server is called Alpha, and runs HTTPS frontend:"beta":http cause me to die.
- ChrisMarshallNY 3y agoI find “self-documentation” often doesn’t actually work. It’s great in theory, but often falls down, in practice. I tend to preface my config stuff with fairly substantial comment blocks that discuss the reasoning behind the configuration. Here’s an example: https://github.com/LittleGreenViper/LGV_MeetingServer/blob/master/Tests/config/LGV_MeetingServer-Config.php https://github.com/LittleGreenViper/LGV_MeetingServer/blob/m...
- bombcar 3y agoBy "self-documenting" I mean things like: # Diff for interactive merges. # %s output file # %s old file # %s new file merge="sdiff --suppress-common-lines --output='%s' '%s' '%s'" it's useful the first time you dive in, not having to read the man page. But over time, the comments can get out of sync especially if you don't carefully merge in the package-maintainer's version every update.
- somat 3y agoI like how the openbsd project does it. They have a parse.y that sort of gets traded around and joins new projects. Nothing super formal but it does mean most openbsd service configuration feels like each other. but each config is tailored to it's application. and being properly parsed the error messages can be better. In fact that is my biggest beef about yaml, I mainly use it in the context of ansible, and the parsor usually has no clue where in the file the error actually is. You have to depend on remembering where you last edited to actually find the error. My other big problem with yaml is that the ansible context is trying very hard to make it a programing language... And while it is an okish config language it is a terrible programing language. In fact this is a common problem with many complex environments. They want to try and push this complicated setup into a config file and claim "look it is easy, no programing required" when really what they have done is to push a programing situation into the worlds worst programing language. see also: xslt
- deleted 3y ago[deleted]
- stormbeta 3y agoFor human-maintained config, TOML is only "better" when the structure is so flat that it's almost indistinguishable from an INI file. Anything more complex and it becomes one of the worst choices due to the confusing/unintuitive structure (especially nesting), on top of having less/worse library support. YAML's structure is straightforward and readable by default, even for fairly complex files, and the major caveats are things like anchors or yes/no being booleans rather than the whitespace structure. I'd also argue some of the hate for YAML stems from things like helm that use the worst possible form of templating (raw string replacement).
- kstrauser 3y agoI'm with you on all that. I think YAML's fine, and I like it way more than TOML for non-trivial files. I think Python's pyproject.toml is a great use of TOML. The format is simple with very little nesting. It's often hand-edited, and the simple syntax lends itself nicely to that. Cargo.toml's in that same category for me. However, that's about as complex of a file as I'd want to use TOML for. Darned if I'd want to configure Ansible with it.
- linsomniac 3y agoAgreed, I do a lot of Ansible, and it took me a while up front, but I've become pretty accustomed to YAML. Though I still struggle with completely groking some of the syntax. But, I recently took a more serious look at TOML and felt like it'd be a bear for Ansible. A few months ago I made a "mini ansible / cookie cutter" ( https://github.com/linsomniac/uplaybook https://github.com/linsomniac/uplaybook ), and it uses YAML syntax. I made a few modifications to Ansible syntax, largely around conditionals and loops. For YAML, I guess I like the syntax, but I've been feeling like there's got to be a better way. I kind of want a shell syntax, but with the ansible command semantics (declarative, --check / --diff, notify) and the templating and encryption of arguments / files.
- earthboundkid 3y agoWorse is better: TOML discourages nesting and nesting is bad, TOML is good. :-)
- burnte 3y agoLooks like INI files from Windows 3.
- tomphoolery 3y agoin terms of something i'm shipping to users, i would much rather have to worry about the nuances of TOML than of YAML. with TOML, i don't have to worry about e.g. remote code execution because someone figured out a clever way to trick my yaml into running arbitrary code somehow. that kind of shit is annoying. is it uglier? sure. but it's peace of mind... in terms of config i'm using myself, say Kubernetes stuff, i really love YAML...because i know exactly what it's doing and i generally keep things simple. it's nice for that, it just does way too much IMHO...
- c7DJTLrn 3y ago>While YAML is far from perfect, it's fine for random config files written by humans If only Kubernetes hadn't gone and used it as the markup language of choice to represent... everything.
- Spivak 3y agoNo no no, k8s mistake was actually not using YAML hard enough. They built an object system on top of a format that can act as a typed serialization format for generic objects and then decided to just ignore all that and implement it on top of primitive types
- allarm 3y agoTangentially: there are some objects in the Kubernetes configuration that require the data to be base64 encoded (I think it's secrets and config maps, probably something else). When I was preparing for my CKA certification, I used the (most?) popular course that introduced base64 encoding as a _security measure_. I think that also says something about the state of the industry.
- jeroenhd 3y agoI don't know. JSON isn't much better. { "servers": { "alpha": {"ip": "10.0.0.1", "role": "frontend"}, "beta": {"ip": "10.0.0.2", "role": "backend"}, } } YAML also isn't great: { "servers": { # Frontend server is called alpha "alpha": {"ip": "10.0.0.1", "role": "frontend"}, # Backend server is called beta "beta": {"ip": "10.0.0.2", "role": "backend"}, } } Or, depending on your preference: servers: # Frontend server is called alpha alpha: ip: "10.0.0.1" role: "frontend" # Backend server is called beta beta: ip: "10.0.0.2" role: "backend" I don't think XML is much better or worse: <?xml version="1.0" encoding="UTF-8"?> <servers> <server id="alpha" ip="10.0.0.1" role="frontend" /> <server id="beta" ip="10.0.0.2" role="backend" /> </servers> All of them suck in their own way. All of them work fine with autocomplete, type analysis, and autoformatting. The more things change, the more they stay the same. JSON lacks comments, that's the biggest differentiator in my opinion.
- mianos 3y agoJson5, although not widely adopted. Has // comments and /* block comments. It also allows additional trailing , in lists. Something I hate but is a great feature if you use a macro system on top of it. (Like jinja2).
- jeroenhd 3y agoJSON5 does, but most software just does plain and simple JSON. I haven't seen it used outside some Javascript webdev environments. The JSON5 docs also seem to be specifically targeting Javascript development. If you're sticking to certain variants, you may as well use YAML, which supports JSON notation, as well as comments and various other improvements.
- mianos 3y agoIf you use python, there is an excellent json5 module. But true, it may not be as well supported by other languages. I am not sure I may as well be using yaml. I don't like it for the multiple reasons in the OP and this thread. If you are using python, I have found it to be quite easy to support both json5 and yaml, as well as converting between them for people who feel strongly about yaml. Not trivial but low effort.
- matheusmoreira 3y agoI agree. YAML with strict typing is nice enough. I just don't like TOML. Just rubs me the wrong way for some reason. Don't know why.
- richbell 3y agoTOML's nested array/object syntax is awful. At a glance, it's nearly impossible to tell whether something is a parent, child, or siblings node.
- hotnfresh 3y agoI love it. Was so happy to see that syntax when I first encountered Toml. Hierarchy is always clear without having to scroll, and snippets retain context.
- throwawaaarrgh 3y agoYaml is literally not designed to be written by humans. It's a data serialization format, not a configuration format.
- totallywrong 3y agoAnd yet it's the only one out of all those mentioned that can be written with ease by humans. After a short while you can do several levels of nesting without thinking about it. For all its issues, it's by far the most practical which is why it won.
- throwawaaarrgh 3y agoPractical but incorrectly used. We should correct the misunderstanding so that people don't continue to make similar mistakes, inconveniencing themselves and others.
- wheresmyshadow 3y agoi agree, while YAML has its problems, it is good for human-written content, especially when it's not too deeply nested. in short: all these have their use-cases. i use YAML where it fits and TOML where it fits better. I never use JSON because JSON is just for machines, I generate JSONs.
- crabmusket 3y ago> I'd echo the linked article's argument back: I don't know of a case where XML is the best option. From the article: > “I’m making a new kind of book, and I need to annotate all of the verses in the Bible, and have the chapter headings and stuff.” XML is a markup language, and works great for marking up text. It came out of SGML and attempts to make machine-usable documentation. I'd favour its use in something like a datasheet, which is a combination of human-readable information, nested objects, and lots of stuff that needs to be machine parseable in fairly precise ways. IMO it also works "fine" for other structured document formats that aren't text, like SVG, but that's not a strong opinion. JSON and other formats compete more sensibly here, but I'd never want a protobuf-based format for... writing an essay, for example.
- visarga 3y agoXML is pretty good for information extraction with LLMs. It will parse your input text into a tree structure. JSON and YAML will conjure slightly different skills from the LLM. Maybe it all comes from the slightly different applications of these formats in the training corpus.