4 ms·
Comments are important ina format that's being used for configuration as JSON is. Commenting out things makes for easier revert if something doesn't work. Havin
by maxxxxx 10y ago
Comments are important ina format that's being used for configuration as JSON is. Commenting out things makes for easier revert if something doesn't work. Having a Line of comment in front of each setting is also a good thing. This is just basic practicality.
You can't easily append something to an already existing JSON file. You have to decode the whole thing first and then write it back whole. XML has the same problem. That's why I said we replaced one bad format with another.
JSON is not an improvement over XML. It replaced one set of weaknesses with another.
- IgorPartola 10y agoMaybe we shouldn't use JSON as a configuration format. There are numerous better alternatives such as INI files and YAML.
- maxxxxx 10y agoI personally use INI files quit a bit but the cool kids insist on JSON.
- vram22 10y agoINI files are cool, IMO [1]. Though they may have originated in Windows or DOS, other tech uses them too nowadays (and from long, of course). Some languages must have support for INI files in their standard or 3rd-party libraries. I know Python does, in the ConfigParser module. In fact, I'm currently using it in a project I'm working on for a client. [1] I think they are cool because of their simplicity - it is just a two-level hierarchy - sections and options within sections. And options are key-value pairs. For many applications, this is enough, and any format that supports more may be overkill (though would still work). Edited to add the [1] footnote.
- davexunit 10y agoJSON is not for people to write, despite what people try to do. It's for machines.
- pg314 10y agoFrom [1]: "JSON (JavaScript Object Notation) is a lightweight data-interchange format. It is easy for humans to read and write." [1] http://www.json.org/ http://www.json.org/
- davexunit 10y agoIt may say that, but it's main use is a serialization format for machines. The lack of comments makes it apparent that it is not for people. When you want comments, what you actually want to do is write code in a real programming language.
- matt4077 10y agoOr, maybe, our tools should evolve with an eye on how they are actually being used. JSON/YAML/TOML/INI are all intended to store arbitrary data structures, and are all required to be written and read by algorithms. It doesn't make sense to split that world into "these are usually created/consumed only by software" and "these are for humans".
- maxxxxx 10y agoThis whole thing is just a variation of the "you aren't doing it right" syndrome. Be it Scrum, OO, FP, XML, JSON, whenever you criticize one of them people will tell you "this is not what it was intended for" even though a lot of people use it that way.
- Spivak 10y agoBut the more valid form of this argument is "not the right tool for the job". Trying to be all encompassing is how we wound up with XML.
- vinceguidry 10y agoI'd much rather deal with JSON than XML. XML is a document format, JSON is a data format. You extract data out of documents. JSON is 10 times easier to traverse than XML. XML is so difficult to traverse that you have to use a special language to do it cleanly, XPath. JSON, you just read it into whatever hash map data type your language has built-in and use your standard library.
- jimbokun 10y ago"XML is a document format" And works very well as a document format, and JSON works very poorly as a document format! So if you have documents (a novel, an article, a manual, etc.), XML is still a very nice choice. But was a mistake to use XML as a data format. (Just elaborating on your point.)
- maxxxxx 10y agoHow do you know that you are dealing with a document or data? Isn't a document just data too?
- vram22 10y agoI'm not an expert on the difference, but informally, I'd say that the difference is this: a "document" will have more and/or larger passages of text, and the fields are mainly meant as metadata to add meaning to it. A good example would be a real document like a book - when stored in an XML file, a lot of the content would be the text of the book, and you would have some XML elements like <book>, <chapter>, <section>, <TOC>, etc. But for "data", a good example would be an invoice or a purchase order or a part record - while they do have text, it will be mainly in the form of structured fields (typically not too long, unlike a chapter or section in a book), which can again be stored in XML elements. And this is where the siblings and others are arguing about - which (XML or JSON) is a better format for what type - document or data.
- jimbokun 10y ago"(a novel, an article, a manual, etc.)" So something meant to be read by humans. XML is nice for marking up the actual text with structure like chapters, sections, footnotes, references, formatting, etc. (thus, the ML in XML comes from "markup language") With JSON, there isn't really a notion of prose text to "mark up". It is structured data meant to be processed by machines. (Of course it is useful for humans to read and write JSON sometimes, but JSON is primarily meant to be input to or output from some computing process. You wouldn't sit down to read a JSON doucment unless you are some super weird programmer dude.)
- badthingfactory 10y agoThe mistake here is using JSON for configuration.
- always_good 10y agoThe creator of JSON is right: without comments, people won't be tempted to encode directives in comments like we have with XML. Want comments? Pipe through json5. Still vastly simpler than XML. It's hard to take people's criticism seriously every time JSON comes up. There's a sibling comment that even suggests that it's a mistake to use JSON for config in the first place. C'mon.