7 ms·
Comments are a great idea... for a configuration format! They're really bad for a data interchange format though, because people inevitably start putting impor
by seagreen 6y ago
Comments are a great idea... for a configuration format!
They're really bad for a data interchange format though, because people inevitably start putting important data in them and you end up with two different ways to write strings, one of which isn't supported by every parsing library.
Thus each discussion of JSON ends up being two groups talking past each other, the people using it as a configuration format who lament the lack of comments, and the people using it as a data interchange format who celebrate it.
The solution: since it's too late to add comments now, don't use JSON as a configuration format.
- Tokkemon 6y agoSo Yaml?
- seagreen 6y agoYAML's way, way more complicated that JSON. To pick one rough measure, the spec is about 7x as long. It includes a bunch of things that could be seen as negatives, such as nine(!) different ways to write multi-line strings (https://stackoverflow.com/questions/3790454/how-do-i-break-a-string-over-multiple-lines/21699210#21699210 https://stackoverflow.com/questions/3790454/how-do-i-break-a...). I don't have a single competitor to recommend, but JSON5, TOML, JSONC (mentioned in a sister comment), or something else along those lines might be better. I'd probably just go with whichever of those is popular in your community.
- mpfundstein 6y agoi really like hashicorp hcl. more than json. (and yaml is TERRIBLE)
- andybak 6y agoYAML might be terrible for the reasons given elsewhere but I really want something YAML-like (maybe TOML, maybe something else) For me, readability is king both for myself and because I sometimes want non-developers to be able to hand-edit files. Any curly brace format is a non-starter. Too much clutter, too easy to create invalid files that aren't obviously invalid at a glance. Significant white space does have the advantage of meaning exactly what it appears to mean and being intuitively understandable to most people.
- wayneftw 6y agoJSONC is a thing and has both of those features. VS Code used it all over the place.
- rumanator 6y agoOP did said that those features are good for a config format, and that's precisely how vscode uses it. For data interchange formats comments do presents major problem.
- tabtab 6y agoRe: "[Comments are a] bad for a data interchange format though, because people inevitably start putting important data in them" Any feature or tool can be abused and misused. Comments are useful for configuration files, period.
- tinus_hn 6y agoAdding comments to configuration files means you can’t manipulate these files automatically. The advantage of manual configuration and comments has to be pretty great if it has to balance against losing GUI configuration and the other features that depend on automatic manipulation of configuration.
- twblalock 6y agoI automatically manipulate configuration files that contain comments all the time. If that's not doable then the tooling is the problem.