4 ms·
It may be used as such but it shouldn't be. YAML serves this purpose much better. JSON works better as a language independent serialization format that is inci
by crdoconnor 9y ago
It may be used as such but it shouldn't be. YAML serves this purpose much better.
JSON works better as a language independent serialization format that is incidentally readable.
- sametmax 9y agoYeah json is a fact of life, the fact yaml exists doesn't change that. Actually, toml is even better than yaml and yet...
- crdoconnor 9y agoTOML's array/table syntax is kind of confusing, especially when you're a few levels deep. Having meaningful whitespace in YAML makes it clearer. It's also kind of messy when you have a lot of multiline strings.
- NateDad 9y agoMeaningful whitespace is horrid. I speak from 3.5 years of working on s project that exclusively used yaml as configuration. Yaml is horrid. Toml is way better. Yes, multilayered objects in toml are ugly. Don't make your users created multilayered objects for their configuration. That's just a bad UX regardless of the language.
- guitarbill 9y ago> Meaningful whitespace is horrid Millions of Python programmers might disagree, not to mention that most programmers using languages with meaningless whitespace (as far as the computer is concerned) still put whitespace in there, because humans. And it isn't like INI is a great experience, either. Flat configs suck in their own ways.
- krapp 9y agoIt's weird that a language with the mantra "explicit is better than implicit" has, as a core feature, braces implied by the negative space of the left-hand margin of a text editor. >And it isn't like INI is a great experience, either. Flat configs suck in their own ways. Yes, INI isn't great, but people who object to significant whitespace don't object to the "whitespace" part, they object to the "significant" part. That code could not compile or have scope errors because of one extra space or because a space replaced a tab just seems absurd to some people. This is something about which reasonable people can disagree.
- falcolas 9y ago> It's weird that a language with the mantra "explicit is better than implicit" The lack of braces enforces a certain style - something that can be found throughout Python. For example, the lack of multi-line lambda statements. > braces implied by the negative space It's easier to think of it in the same way that the compiler does: indent and dedent. Indent? Creating a new scope. Dedent? Exiting the current scope. All of the "constant 4 spaces" and "spaces instead of tabs" simply makes it easier for humans to interpret the indent and dedents visually. In my experience in writing code in multiple languages: even when using braces you, the coder, still effectively require indentation to visually parse blocks. Yes, copying and pasting code is a touch harder, and most text editors are too lazy to parse for indents and dedents, but the first is mitigated by applying basic DRY principles, the second by installing a python-aware plugin.
- guitarbill 9y agoThe INI example is in response to "Don't make your users created multilayered objects". Personally, I cannot stand TOML, but there's no accounting for taste. I think the significant whitespace is a pragmatism thing. If you're already doing it, do it consistently, if you're already doing it consistently do you really need brackets? The answer is no, and the added bonus is you (and everybody else) is forced to do the whitespace consistently. I'll take a consistently formatted codebase over inconsistencies any day!
- rhencke 9y agoXML was a fact of life in the 90s - inescapable. Things can change. Push the world forward. Think of little things you can do that make the world of development the world you want to be in.
- mschuster91 9y agoYAML can go off and die in a fire... especially because it cannot transfer the data type, which JSON can: you have either an integer, a float or a string. Also some libraries want the values escaped, some not, some barf on non-alphanumeric keys... JSON is pretty much standardized across the board.
- nly 9y ago> you have either an integer, a float or a string. JSON doesn't have "integers" and "floats", it has "numbers" which are are expressed in decimal scientific notation. There's no guarantee an implementation will let you distinguish what was parsed, and the numerical precision and range of interoperable JSON is undefined. The bottom line is JSON is a risky proposition for financial or scientific data exchange. And before you say JSON numbers are de-facto IEEE754 doubles, bare in mind that most JSON implementations can't roundtrip them properly.[0] A symptom of everybody wanting to write a toy implementation. [0] https://rawgit.com/miloyip/nativejson-benchmark/master/sample/conformance.html https://rawgit.com/miloyip/nativejson-benchmark/master/sampl...
- callumlocke 9y agoI use YAML all the time (for config) and the things you mention have caused no more than one minute's frustration in my life. JSON is great for serialisation, YAML for little config files that need frequent hand-editing during development.
- NateDad 9y agoYaml is terrible. The fact that there are so many optional and different ways to format things and the fact that it has significant white space means it's horrible to hand edit. I'd much rather hand edit json. At least it won't care if I accidentally use a tab instead of two spaces. But of course toml is superior to both because it has comments and no significant white space and the comma at the end of lists is optional.
- sebcat 9y agoHere are some examples: https://github.com/cblp/yaml-sucks https://github.com/cblp/yaml-sucks TBH, common JSON implementations have their problems too. Integer size and integer/float (de-)serialization tend to be somewhat interesting at times. I've even seen implementations serializing JavaScript objects as JSON (e.g., {foo: 2} instead of {"foo": 2})
- krapp 9y agoLua tables are better than both, in my opinion. Simpler than JSON, allows for comments, and whitespace is not syntactically significant.