What's Wrong with StrictYAML ############################ :category: Misc :tags: yaml, strictyaml :date: 2020-05-29 05:48:00 +0300 .. _StrictYAML: https://hitchdev.com/strictyaml/ While I'm still delaying my position on TOML vs YAML holy war let's look at the StrictYAML_. StrictYAML is a type-safe YAML parser that parses and validates a restricted subset of the YAML specification. Seems great but `let's look at the removed features list`__, Implicit Typing to be precise: .. TEASER_END .. __: https://hitchdev.com/strictyaml/features-removed/ **Implicit Typing** .. code-block:: yaml x: yes y: null Example pyyaml/ruamel/poyo: .. code-block:: python load(yaml) == {"x": True, "y": None} Example StrictYAML without schema: .. code-block:: python load(yaml) == {"x": "yes", "y": "null"} What's wrong with this? Well, technically `removal of these "features" is good and desired`__ but it makes StrictYAML incompatible with YAML. So yes, StrictYAML spec is a subset of YAML spec but StrictYAML itself is not a subset of YAML, it essentially becomes a distinct language. StrictYAML file cannot be reliably parsed by a generic YAML parser. .. __: https://medium.com/@lefloh/lessons-learned-about-yaml-and-norway-13ba26df680 This can be fixed by making string syntax always explicit but judging by `author's position on syntax typing`__, it won't be. .. __: https://hitchdev.com/strictyaml/why/syntax-typing-bad/ It also gets worse: Example StrictYAML with schema: .. code-block:: python load(yaml, Map({"x": Bool(), "y": Str()})) == {"x": True, "y": "null"} Schema induced type casts? Srsly? `In no definition`__ of `schema`__ that `I've found`__, `practical or theoretical`__, schema is directly responsible for anything but validation. Schema definition must not influence the process of parsing, it's not why it exists. This not only makes StrictYAML even less compatible with YAML but also unleashes even greater evil than it tried to solve. .. __: https://en.wikipedia.org/wiki/XML_schema .. __: https://json-schema.org/ .. __: https://blog.picnic.nl/how-to-use-yaml-schema-to-validate-your-yaml-files-c82c049c2097 .. __: https://www.sciencedirect.com/topics/computer-science/document-schema Interestingly, all other features are removed accurately and it really improves the language. Except maybe I don't agree about flow style. It makes YAML a superset of JSON which was announced as a feature and in my practice it was very useful from time to time. I see no real gain in removing it but at least it was done quite cleanly without breaking compatibility.