by hombre_fatal · 7y ago · 0 comments
Also, check out JSON schema and its integration into tools like VSCode. VSCode gives you generalized autocomplete on its own config and known config formats like package.json by pulling in json schema definitions. It works well. Easily a better experience than the executable-program-as-config I learned to hate in the JVM world, and easily better than ad-hoc config like Caddy's.
I have a more practical pitch: make your tool consume json5 as well as json.
Also, it's telling that the author wasn't even willing to stick their neck out enough to pitch a single solution. I guess in the end they realized there are always trade-offs and any alternative would have its own downsides. :) But I'm getting a bit fatigued of these you're-doing-it-wrong posts. They are effortless to write and they're like crack to HN. I can complain about literally everything.
JSON is a fine format for storing configuration data, and any reasonably structured data. So is XML, protocol buffets, what have you.
JSON is a poor format for humans. For a configuration file that an actual human would edit by hand, and read and try to understand later, JSON is a pain.
Comments are mostly useless in a machine-generated and machine-consumed file. They are indispensable for humans, because they are a link to what machines are not doing.
Nice formatting is useless for a machine-consumed file, because they process a stream of bytes. They are indispensable for humans who recognize text very differently.
This boils down to one thing: config files are source code, and need all the amenities that make source code comfortable for humans.
I didn't. There wasn't much to the blog post. In fact, the blog musings are the same criticism we've heard a thousand times. But please don't suggest that I missed some deep point in a trivial blog post when you really just mean "I disagree".
I even pointed out a real-world concrete example where JSON config is made pleasant to edit by hand for humans: an IDE like VS Code that pulls in JSON schema.
Though since you only doubled down on the blog post's opinion instead of responding to a single point I made, can I say that you missed the points of my comment? You didn't even address my criticism by pitching an alternative. How are we supposed to have a conversation?
I think the debate here is what "editable by humans" means. If you're using a tool for editing JSON like VS Code, I don't believe you're really editing it by hand. You're using a program that has specific things for JSON that give you to have a pleasant experience editing. I believe editing by hand means using a standard plain text editor and it's a lot worse.
Formats that use braces are relatively easy to parse by machines but can be harder to read by humans. Utilizing white space makes things easier for humans to read. A JSON file could have everything on one line. But something like YAML it forces you to use white space and new lines which helps humans to read it.
The only significant thing missing from JSON is comments. JSON5 or convention can solve that, so it's not as bad as you'd expect.
Still, editing JSON directly by an IDE that still exposes its syntax is "editing by hand", just as editing C in Vim with ctags is still editing by hand.
I do have to note though that VSCode uses JSON with extensions. Most obviously, it allows comments. But there are other minor things that make it easier to write (and parse) - e.g. it allows trailing commas in literals.
But do you know what sucks even harder? XML. If I can replace an XML configuration file with JSON then screw it.
In my experience, the biggest reason people hate it is because it has too many ways of structuring data, and it allows people who design the schemas to go overboard. Attributes or child nodes? Multiple namespaces or just extend the one you have? CDATA or embedding?
That said, simple XML is as good as simple JSON. XML is fine if you keep it simple when designing the schema. AND of course one can screw up with JSON too. But after almost 20 years of people over-engineering their XML schemas, I can't fault anyone for choosing a simpler data format.
Recently I've had to work with XML config files for a tool called Oozie, which is a data pipeline scheduling tool within the hadoop/spark ecosystem, and it has been soul crushingly tedious for me. Everything feels verbose and opaque, the documentation seems to prioritize enumerating every possible configuration option over providing minimum viable configs for common use cases.
JSON configs often just feel more simple and developer friendly. I'd say this has less to do with technical differences between JSON and XML and more to do with how "modern" software systems have been designed to be more ergonomic for developers/administrators and these modern systems happen to be more likely to use JSON.
It's also fun to hear non-technical people at work talk about "Jason files".
People can easily read and edit it with deeply nested structures, attributes, and even malformed data. Frontend frameworks using components and variations like JSX also maintain the same style because it's very natural to use.
Now try taking a typical HTML document and expressing it in JSON. Even an empty page would be completely unmanageable without tooling. People have a strange reaction when they hear "XML" but it's much more structured, usable, and widespread than you think.
Also HTML is not XML. HTML is non-strict (the spec is it’s parser not its format). HTML doesn’t have schema files. HTML doesn’t understand self-closing tags. HTML does have void elements (img, br, input, etc). HTML is designed for humans to write. And it’s a tool fit for its purpose, unlike the abomination that is XML.
HTML is not XML and even then few developers today use HTML without some sort of processing involved. HTML is also not a language used for configuration files, so it is really off-topic.
The question is, do people prefer XML configuration over JSON configuration. The answer is that people generally prefer JSON. JSON just maps far better to data types we use in everyday programming. Have you seen some of the common ways of expressing key-value pairs in XML? It's horrible.
> Now try taking a typical HTML document and expressing it in JSON.
That's not the problem anybody is trying to solve here. We're talking about configuration files, not complex documents. But let's say I wanted to solve that problem, the representation would look like this:
Not that bad at all.
const config = require('config.json');
console.log(config.apiKey);
With XML you often have to use things like XPATH etc. to extract the data which is a lot more effort.
Slightly less so as a JSON document, IMHO.
XML has other problems though.
https://stackoverflow.com/questions/48998034/does-toml-suppo...
To me it’s an improvement over JSON which is an improvement over XML.
But I'd posit that most - but not all - of the issues with xml config files have little to do with xml per se, and everything to do with the crazily detailed stuff people squeezed in it. You don't have to stick everything in a namespace, and nest even trivial things 3 deep with annotations for obvious types. And if you do those things in json it turns into a mess too.
SOAP is a perfect example of that. But: just because soap is messy doesn't imply xml everywhere has to be that.
But sure, xml has some downsides. Then again, so does json. Oh well!
Cant do that with json.
some_collection:
- first_entry
vs some_collection:
first_entry
When you're staring at a non-trivial YAML file, it's very hard to spot these errors, and you'll potentially get some very weird behavior in whatever is depending on the config.I do know about a number of gotchas, and stepped on some briefly. Yaml is not ideal, but its set of tradeoffs is more suitable for human-editable configs, from my point of view.
It doesn’t matter the language or syntax, if the unit of structure doesn’t fit on the screen, it’s hard to work with.
One example from a larger file:
networks:
macvlan51:
driver: macvlan
driver_opts:
parent: eth0.51
ipam:
config:
- gateway: 192.168.51.1
subnet: 192.168.51.0/24
Maybe I'm just getting older and dumber, but that hyphen under config seems completely arbitrary to me (and the necessity of it is poorly documented in the manual). This gets magnified to the extreme as your config file grows. Maybe this is a list of objects under a key? Who knows.Edit: OK, it looks like hyphens indicate arrays in the schema but for me it feels like a guess as to which one of these to use for each particular case.
I have never understood this argument. I'm not saying it's the best, but I find it much much more readable than yml or xml.
But yes, if every implementation of JSON moved on to JSON5, I don't think we'd be having this discussion.
Example is below where an application could either extract values at startup, or is extracted when code is built and deployed?
# My App
## Intro about My App
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
## Prod Server Settings
| Host | Port |Operating System| Type |
| -------------------------|:-------------:|:--------------:|--------|
| webserver1@myapp.com | 80 | Debian |Web |
| webserver2@myapp.com | 80 | Debian |Web |
| db@cloud.com | 1433 | aws |Database|
| webservice.com/api | 80 | aws |Database|
---------------------------------------------------------------------
## Support Information
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
## Application Roles
|Name | Active Directory Group |Description |
|-----------------------|------------------------|-----------------------------------------|
|System Administrator | MyApp.SysAdmins | Details who should be assigned the role.|
|Finance Administrator | MyApp.FinAdmin | " " |
|Finance Delegate | MyApp.FinDelegate | " " |
|Finance Analyst | MyApp.FinAnalyst | " " |
-------------------------------------------------------------------------------------------|Depends on which kind of humans.
For the regular non tech types I agree JSON is poor. A couple of years ago I created a mini spec for a config file so that very low tech paper designers could configure an interactive book.
For programmers, JSON works fine in my experience.
The author mentions this, and I very strongly agree. What JSON significantly misses is the ability to have comments in your configuration files. I'm not going to hold up the Apache config files as an example of amazing config formats, but... here's an example: https://svn.apache.org/repos/infra/websites/cms/webgui/conf/...
That's awesome. It describes options that are available and not enabled, and what they do. Right. In. The. File. Comparing that to, say, webpack config... there's a pile of research needed to figure out what options are even available, let alone what they do.
All the other arguments for or against it boil down to personal preference, but not having comments is a real miss.
Cloud Formation is a great example of the failures of JSON. Specifying just a single dynamo table with indexes and scaling roles in JSON is a hard to read cluster of a mess. Even with a good idea and json collapse / expand help, large json files are just insufferable to deal with as a human
Programmers will maybe cope better but just being a programmer doesn't make you magically immune to poor readability and lack of comments.
Most of the points in that article apply to programmers as much as non-programmers.
(I agree there is a reasonable debate to be had about programmability - I'm on the fence about this one)
I don't hate it, but I really dislike it. It's definitely better than JSON for this purpose, but it's still quirky and a bit of a pain.
The use of brackets means if something is broken, you'll know explicitly because your IDE will throw a fit. Formats that are white-space dependent can have subtle errors that aren't easily recognizable on first glance.
The 2 problems with JSON are multiline string support and comment support, but JSON5 solves both of those problems. Sure JSON5 isn't JSON, but YAML isn't JSON either. No matter what you're going to need a library to parse a config file, so why not stick to something based on a widely used data-storage format?
{ useFluxCapacitorComment: "Enables time travel. true or false", useFluxCapacitor: true }
I don't mind the formatting, but I'm a professional developer, so my tolerance for complex UIs is abnormal.
Written on mobile, so that JSON may look like garbage.
E.g: npm/yarn will complain loudly if you add unexpected lines in package.json IIRC.
But comments are often code smell—a crutch for poor identifier naming and design. If your names and design are well thought out you rarely need comments and the consumer of your code should be able to understand it using the statically checked source alone—-versus manually having to parse your unchecked human language documentation.
Comments are important when they express things that code cannot.
Examples:
// See ticket XYZ-123 for discussion and rationale.
// We are sidestepping a bug in Docker 3.x here.
// TODO: Allow queue size per service version. Currently we're using max size for all.
Use as explanation of intent.
Use as clarification of code.
Use as warning of consequences.
Here's a link to a well-known recent book, half of which is pretty much about why those points are a real and frequent thing, and why code should be much more thoroughly commented than it's recommended by the usual philosophies.https://www.amazon.com/Philosophy-Software-Design-John-Ouste...
["DoStuff", "EvenMore"/, "ops go back :("/]
Sure, but how often does that happen?
I can at least imagine such a configuration file format could be both simple enough for human and machine to reason about, and flexible enough to add value over (say) json. But the devil is in the details; and it's not always immediately obvious what's too complex.
In any case, json5 looks like what json should have been from day 1; several of the really critical improvements were common JS practice when json was invented.
I'm a little worried about the IdentifierName extension, since that's more than what javascript itself allows (no reserved keywords!).
But json5 is also an interoperability problem. The nice thing about a (good) standard is the that if it works someplace, it'll work anywhere. Add json5 into the mix, and that's not the case anymore.
Then again, there aren't a huge number of plausible successors to json, so maybe this is the best we can hope for. And it's trivial to down-convert to plain json, which means it's not too bad, I guess?
I wish json5 simply worked everywhere ;-).
https://github.com/lightbend/config/blob/master/HOCON.md#goa...
TOML is fine.
shivers
I wrote this after getting annoyed with MediaWiki's new extension format which uses JSON files to set up the extension. What I wanted to do is not include some CSS if a certain plugin is loaded, and that's pretty much impossible to do in a declarative configuration file. Using a JSON file – or any other declarative config – to describe how code works is not a good idea IMHO (although it's probably fine to add basic metadata).
The worst case of declarative programming gone wrong that I've seen is probably k8s.
I can't really judge your Gradle example, as I've never worked with Gradle (or Java in general).
> I'm getting a bit fatigued of these you're-doing-it-wrong posts
I agree, and I would rename the article if I hadn't put the full title in the URL (I have since stopped doing that exactly because I wanted to rename this). In my defence, at the time I was annoyed with MediaWiki, PHP, this JSON stuff, and the reasons I even had to work on MediaWiki in the first place (which is a long story involving a lot of drama).
That being said, I think using JSON as a human-editable configuration format is, quite frankly, never a good application of the tool. I can't think of any cases where it's the best tool, chiefly due the lack of comments, but also because it's kind of a pain to write. Variants which allow comments – such as JSON5 – are okay, but that's no longer JSON.
> You can't even figure out what the dependencies are going to be for some Gradle projects without executing them
This sounds like an issue of Gradle, not of programmable configs in general.
Not every config file needs that, but a config file for a build system definitely needs that. Otherwise your build system becomes too restricted and you must either write your logic in plugins or use another scripts along with your main build tool. Both options are bad.
I'm not even sure that build.gradle should be called a config file. It's a build script.
Originally, the whole point of using configuration files for builds was to eliminate the programmatic element where you used lots of little scripts to run builds. Config files are easy to read and reason about.
> Programmatic configuration allows e.g. specify some library version once (e.g. springVersion) and use it for 10 dependencies as a variable
Declarative syntax can also include variables which can't be reassigned to later.
Gradle's original marketing message was based around its syntax, i.e. Apache Groovy being easier to read than XML, which is true. But providing the programmatic ability of Groovy as well is a step backwards for configuration best practice, ultimately resulting in an increase in technical debt. Thankfully, almost all the Gradle build scripts out there are simple 20-liners which don't use programmatic logic.
Gradle ought to follow the example of Jenkins pipelines, which later provided a Declarative Syntax as an alternative to Groovy to mitigate this very issue.
For the same reason that I would want to figure out if my script type-checks without executing it - making it easier to avoid bugs and reason about the program.
if you ever have a non-programmable config file, then at some point someone will make a turing-complete programming language which goes on top of your tool.
I don't understand how anyone who ever used gradle or even maven and went somewhere else can actually say that
Gradle is simply amazing and literally don't know what could be better about it. The link posted is so trivial compared to it's power, it's like criticizing a bullet train for the pattering on the seats.
- xml contain comments, sooner or later someone will try to add data to comments, but you already have the thing for data, the format itself, adding data to comments is stupid
- unlike js, in json someone finally said "Enough! There will be only one type of quotes", it makes parser simpler
That's easily the worst argument against comments I've ever heard! Would you argue against comments in code because some jackass could abuse it to insert custom compiler directives or something? Ridiculous. The good comments do easily outweighs any harm some moron is going to do to himself by parsing comments for data.
I don't like XML any more than the rest of you, but praising json for not having comments just smacks of sour grapes.
It's definitely the case that XML has features that aren't needed -- or at least, we've survived without them thus far -- but there definitely feels like more than just a smidge of only realising later why some of that complexity was present. See also: npm vs pretty much any other dependency management system.
inability to properly use a library should not count against it
JSON5 makes things better, but it still requires too much syntactical noise and multi line string values are still not there.
True... for end users, but absolutely not for other developers. I often see this mentality used as a crutch to baby developers from having to write original code.