News for hackers. Stuff that matters.
Re:XML is better than YAML by unscaled on Wednesday September 20, 2023 @11:47PM (#37593004)
> I then built a UI system that works with the XML and generates cofig docs with ease.

I lost you there. Not that I'm criticizing you since I've gone the same route and built a complex UI tool to manage said config (complete with XSD schema validation and config schema migration using XSLT for version upgrades).

But now I realize that modern developers don't want a GUI to manage their config. We want to store it git, review changes and perhaps even write our own automation and templating around it.

YAML is certainly a flawed format for most of these purposes, but so is XML. It is unnecessarily verbose and it carries a lot of complexity which was designed for a highly-extensible generic document format, but not for configuration files. XSD, Namespaces, Entities, Embedded DTD, CDATA blocks... You can't just ignore all of these, and there are very few parsers out there which work on a well-defined subset of XML. And even there, the whole attribute-vs-child-element choice is a giant distraction and constant source for unnecessary bikeshedding.

YAML has serious ambiguity issues, but there are better alternatives that have great library support like TOML. We don't have to go back to the excesses of the early 2000s and use XML as a configuration format.

Re:XML is better than YAML by wsc981 on Thursday September 21, 2023 @12:41AM (#37593289)
I think I’d prefer JSON over both XML and YAML when dealing with config files.

XML is just to verbose, making it harder to parse in my brain.

YAML is whitespace sensitive which I hate in general.

Re:XML is better than YAML by yjftsjthsd-h on Thursday September 21, 2023 @12:49AM (#37593341)
I'm fine with JSON except it doesn't officially do comments, but that's a big deal IMO
Re:XML is better than YAML by sixothree on Thursday September 21, 2023 @01:21AM (#37593486)
Which is especially problematic for config files where you want helpful hints or a place to store the “old value” while you do something else with the app. I have an app where I change a specific config almost every time I use it. I usually just copy the entire darn node and rename it to something that doesn’t get deserialized. Closest I can get to holding the value in a comment.
Re:XML is better than YAML by Koffiepoeder on Thursday September 21, 2023 @01:50AM (#37593685)
Might be interesting to check out json5.

https://json5.org/

Re:XML is better than YAML by FlyingSnake on Thursday September 21, 2023 @04:07AM (#37594603)
This is a great example why we should avoid writing custom DSLs and just use a proper programming language.
Re:XML is better than YAML by eitland on Thursday September 21, 2023 @04:22AM (#37594735)
Then again, Gradle has come to show why that is a terrible idea.

I think at some point 24 out of 28 Gradle projects I had access to at a certain customer had variations in either kotlin/Groovy style or the way they did or didn't use variables, how they did or didn't do loops or maps and what not.

With Maven you (or someone who know Maven) can immediately look at a rather small, very standardized file and start making educated guesses and so can an IDE.

With Gradle you sometimes have to run it to actually know what it will do.

Re:XML is better than YAML by aftoprokrustes on Thursday September 21, 2023 @06:07AM (#37595544)
I had the same experience with Maven vs SBT (scala build system, config is scala). At first it is really cool to have access to a full programming language (in particular when it is the same as the one the project is in, which means that you do not need to "switch brains" when working on the config), but quickly people start trying to be smart or cute, and it becomes a big mess. In particular in Scala, where people _love_ defining new DSLs and favor cuteness over readability. After two years working with SBT I still do not really understand some of the DSLish constructs used in there (and I tried to read the docs).

On the other side I fell in the trap of trying to overcome the limitations of purely declarative config formats by using jinja templates, which also ended up being a very bad idea and a maintenance nightmare.

For most projects, my approach is now to try to be as standard as possible compared to the particular community in the tech at end, and resist the urge to be smart or cute (hard!). Configuration always sucks, and I now prefer to just suck it up and get done with the config part, rather than loosing time reinventing the wheel, ending with a config that still sucks _and_ no one understands.

Re:XML is better than YAML by eitland on Thursday September 21, 2023 @04:37PM (#37603957)
The good thing about Maven is it is XML so everyone wants to keep it as short as possible ;-)

(More seriously: with Maven shorter and more boring is a sign that everything is correctly configured. Maven works by the convention over configuration principle so if you don't configure something it means it follows the standard. Which again means if you see someone has configured for example a folder or something that usually isn't configured it means they have put something in a non standard location.)

Re:XML is better than YAML by JD557 on Thursday September 21, 2023 @04:57AM (#37594994)
I think it's only popular in the scala ecosystem, but I find HOCON to be a pretty nice superset.
Re:XML is better than YAML by frant-hartm on Thursday September 21, 2023 @01:12AM (#37593449)
You know that JSON is subset of yaml, right?
Re:XML is better than YAML by dragonwriter on Thursday September 21, 2023 @01:42AM (#37593618)
Since most people’s (especially critics) understanding of YAML is stuck on YAML 1.1 where that wasn't quite true, probably not.
Re:XML is better than YAML by arwineap on Thursday September 21, 2023 @01:44AM (#37593641)
The commenter said they preferred json over yaml because yaml is whitespace sensitive; Json is not

yaml's feature set is also too broad, forcing safe loaders

Re:XML is better than YAML by bshacklett on Thursday September 21, 2023 @08:14AM (#37596492)
I think the point is that if something accepts YAML, you can feed it JSON without issue.

> yaml's feature set is also too broad, forcing safe loaders

Could you elaborate?

Re:XML is better than YAML by arwineap on Friday September 22, 2023 @02:10AM (#37608467)
Yaml tags allow for serialization of native types, and has been abused to run malicious code.

I think you can also make circular references in yaml effectively making a zip bomb

This is why you have yaml.safe_load in Python and SafeConstructor in Java's snakeyaml package

The end result is that you should not use yaml to handle untrusted data unless you are also explicitly handling it safely

Re:XML is better than YAML by bshacklett on Friday September 22, 2023 @04:54PM (#37617639)
Any de-serialization should be done via safe loaders. Using `require()` or `eval()` isn't something I'd do outside of a very narrow set of scenarios.
Re:XML is better than YAML by arwineap on Saturday September 23, 2023 @04:19AM (#37621541)
The json modules in the same languages doesn't support the madness and doesn't necessitate a safe loader

It's possible someone could come along and write a json library that would support this, but somehow we have made it this far without it and that's a good thing

The point is that yaml and xml both have side effects in the form of require and eval that json won't, and frequently people are unaware of this

Re:XML is better than YAML by bshacklett on Wednesday September 27, 2023 @09:10AM (#37674143)
I feel I must still be misunderstanding something. OWASP has pages of resources which talk about the lack of safety of JSON:

https://owasp.org/search/?searchString=json

Perhaps yaml and xml have _more_ ways to inject behavior into an application, but I would still not consider JSON safe in any way. Why would JSON.parse() even exist if `require()` and `eval()` were safe to use?

Re:XML is better than YAML by physicsguy on Thursday September 21, 2023 @03:27AM (#37594301)
Much easier to have invalid JSON than invalid XML as jsonschema isn’t even close
Re:XML is better than YAML by planede on Thursday September 21, 2023 @06:12AM (#37595585)
XML is whitespace sensitive, unless your particular schema just doesn't care about whitespace text nodes.
Re:XML is better than YAML by mumblemumble on Thursday September 21, 2023 @12:02AM (#37593084)
In XML's defense, the attribute-vs-child-element choice is always obvious and straightforward when you're using it as a markup language. It's only when you use it as object notation that it becomes wonky, because there the choice simply doesn't map to any straightforward characteristic of the problem domain. I'm not sure I want to hold XML responsible for not being good at being something it isn't.

And, on that note, I think that if I could pick as single thing that irritates me the most about YAML, it's that it isn't actually a ML.

Re:XML is better than YAML by unscaled on Thursday September 21, 2023 @12:08AM (#37593120)
I'm not criticizing having attributes-vs-child-elements. The problem with XML is not that it exists or that it is a particularly badly designed markup language.

The problem is that XML is ill-suited for configuration files.

Re:XML is better than YAML by baq on Thursday September 21, 2023 @01:43AM (#37593637)
Yeah JSX and especially TSX would be quite nice. YAML though can’t die soon enough.
Re:XML is better than YAML by moritzwarhier on Thursday September 21, 2023 @07:34AM (#37596113)
You think that JSX would be suited for configuration files?

Why?

I don't understand your comment.

Re:XML is better than YAML by baq on Thursday September 21, 2023 @11:16AM (#37598897)
Because people reinvent half of it, different half every time in each project, and call it 'configuration' which somehow gives them licencia poetica for whatever crazy dung they come up with.

Compare ansible vs helm vs github actions vs literally anything with nontrivial config.

Note that if you asked me for real, I'd be a dhall proponent, but most normal people look at me funny the first time they hear it and then the second time they see the syntax.

Re:XML is better than YAML by moritzwarhier on Thursday September 21, 2023 @01:41PM (#37601166)
dhall looks nice actually! Thanks for elaborating :)
Re:XML is better than YAML by wokkel on Thursday September 21, 2023 @02:42AM (#37593987)
Why? I can store it in version control. I can validate if the file has syntax errors or schema errors etc. etc. With a proper platform it's easy to generate or parse. It allows for both hierarchical structures (looking at you .ini). The only downside might be that you need a larger library to parse it. But i probably encounter xml somewhere along the line anyway due to interactions with a 3rd party system, so that point is moot.
Re:XML is better than YAML by dvdkon on Thursday September 21, 2023 @03:59AM (#37594549)
You have a low bar for config languages. I'd also like one to not be overly verbose, not be clearly intended for markup instead of object storage and not have security issues until you configure the parser just right (though that's often not an issue with configs). XML fails all of these, and YAML isn't much better.

If we're limiting ourselves to just JSON, INI, XML and YAML as potential choices, I get why people cling onto one of these suboptimal choices and then fiercely defend it, but there are other options. There's libconfig, JSON5, Dhall, various interpreted languages...

Sadly these alternatives are far from mainstream and have no support in standard libraries, so I think most developers will continue to pick whichever common option's issues they can deal with.

Re:XML is better than YAML by PH95VuimJjqBqy on Thursday September 21, 2023 @03:39PM (#37603030)
I'd like my config files to have two words in it "do it" and for it to just know what I want.

But at the end of the day that's not possible because reality intrudes. You give up a lot for that lack of verbosity, not everyone will agree that it's a worthy tradeoff.

Re:XML is better than YAML by GoblinSlayer on Thursday September 21, 2023 @09:43AM (#37597502)
It's a noble goal to want a simple configuration format, toml is far from the simplest, line separated options format is simpler. The fact that it needs a parser indicates that it creates a bigger parsing problem than necessary.
Re:XML is better than YAML by dragonwriter on Thursday September 21, 2023 @01:41AM (#37593608)
> And, on that note, I think that if I could pick as single thing that irritates me the most about YAML, it's that it isn't actually a ML.

“YAML ain't markup language” is kinda the whole point.

Re:XML is better than YAML by LukeShu on Thursday September 21, 2023 @01:55AM (#37593710)
For a full year it stood for "Yet Another Markup Language".

First draft: https://yaml.org/spec/history/2001-03-30.html

Last draft calling it that: https://yaml.org/spec/history/2001-12-10.html

First draft with the new acronym: https://yaml.org/spec/history/2002-04-07.html

Re:XML is better than YAML by xorcist on Thursday September 21, 2023 @04:47AM (#37594914)
It's also funny that the file extension YML is the successor of XML, so the rest is probably a backronym from that.
Re:XML is better than YAML by thaumasiotes on Thursday September 21, 2023 @06:28AM (#37595677)
Wouldn't the successor of XML be XMM?
Re:XML is better than YAML by mumblemumble on Thursday September 21, 2023 @08:28AM (#37596619)
Next you'll be telling me Beyonce's sisters should be named Beyoncd and Beyoncf instead of Aeyonce and Ceyonce.
Re:XML is better than YAML by mvandermeulen on Thursday September 21, 2023 @10:32PM (#37607188)
Feyonce can’t get anyone to believe she’s married and Vakira’s has astonishingly honest hips
Re:XML is better than YAML by dragonwriter on Thursday September 21, 2023 @11:09AM (#37598781)
Judging from BCPL, the successor should just be Y.
Re:XML is better than YAML by dragonwriter on Thursday September 21, 2023 @11:07AM (#37598764)
The file extensions for yaml is .yaml, .yml is the alternative because of legacy 8.3 systems.
Re:XML is better than YAML by throwawaymaths on Thursday September 21, 2023 @09:21AM (#37597231)
The thing is if you're using it as configuration language, object notation is correct, not markup.
Re:XML is better than YAML by taeric on Thursday September 21, 2023 @10:30AM (#37598160)
I'm curious why you think that is? Especially since you are likely to want to style the configuration for display to the user in many cases, having it be a document makes a lot of sense.

That is, if the value is something you would expect to be able to show to a user, then it probably shouldn't be at attribute. If it is a value that changes how you would show it, then attribute makes a lot more sense.

I also think a strong adherence to any preference between attribute and markup is a touch too dogmatic. The only real distinction at the language level is if you allow children, or not. If it can have children, it pretty much has to be a child and not an attribute.

Re:XML is better than YAML by throwawaymaths on Thursday September 21, 2023 @11:55AM (#37599540)
Ok forget the difference between attribute and markup. What is the "right" way to think of this:

    <foo>
      <bar>1</bar>
      <bar>2</bar>
      <baz>3</baz>
      <baz>4</baz>
    </foo>
Re:XML is better than YAML by taeric on Thursday September 21, 2023 @12:37PM (#37600189)
Why do you think there is a "right" way?
Re:XML is better than YAML by CableNinja on Wednesday September 20, 2023 @11:58PM (#37593067)
I recently started a new project, and just outright didnt want to use yaml to do it. Sadly, im not everyone, and if i plan to release this project, i need to account for that. Whats a guy to do?

Ill tell ya hwhat... I made some simple functions; one to load any yaml/toml/json from file, by just looking at the extension (and providing an override for not normal file extensions). Another to output any data as yaml/toml/json.

I defaulted to using toml for my project, but have provided ways for everyone to be happy, with zero mucking around.

Aaaaaand for the not so subtle promotion, https://pypi.org/project/atckit

Located in the UtilFuncs class.

Re:XML is better than YAML by elzbardico on Thursday September 21, 2023 @06:12AM (#37595584)
What is the point of substituting yaml for something even worse?
Re:XML is better than YAML by CableNinja on Thursday September 21, 2023 @10:22AM (#37598061)
Worse is subjective.

In any case, the library i linked has the functionality to load any of the three configuration types, so while i prefer toml, if you grabbed my (under development) project, and hate toml, you can use yaml or json, if you wish.

Re:XML is better than YAML by kumarvvr on Thursday September 21, 2023 @12:21AM (#37593191)
I built it to make it so that average users can make their own config. The main system works off on only XML files.
Re:XML is better than YAML by bryanrasmussen on Thursday September 21, 2023 @07:07AM (#37595939)
>But now I realize that modern developers don't want a GUI to manage their config. We want to store it git, review changes and perhaps even write our own automation and templating around it.

not all configurations are maintained by developers, or at least theoretically they shouldn't be.

Re:XML is better than YAML by blincoln on Thursday September 21, 2023 @07:29AM (#37596083)
> But now I realize that modern developers don't want a GUI to manage their config.

I think, like almost all software, it depends on personality and other factors like how frequently someone has worked with a language/tool/etc.

If someone has the traditional Unix "read all the man pages in their entirety" kind of brain, they'll probably never use a GUI.

If someone has more of a "learn by example, then refer to the docs to cover cases the examples didn't handle" brain, a GUI can be a much easier way to clearly expose all the potential functionality of a tool. It's much easier to understand (IMO) than e.g. a template configuration file with every possible option present but commented out.

Re:XML is better than YAML by HelloNurse on Thursday September 21, 2023 @12:11PM (#37599791)
> a well-defined subset of XML

No. You need to define what configuration files are valid or not, but a subset of XML on the basis of syntactic and structural alternatives is lame and nonstandard.

Get a library that parses actual XML, allow anything reasonable as input (for example, no external entities, DTDs, PSVI etc. to keep the file self contained) and "flatten" CDATA sections, entities, namespace prefixes, idrefs etc.