Is YAML one of those things that proper professional programmers need but us amateurs can botch our way around?
Is YAML one of those things that proper professional programmers need but us amateurs can botch our way around?
Yes - I know that some JSON parsers will allow comments and strip them, but IMHO you shouldn't rely on this, and lots of editors will complain if they encounter any non-standard JSON.
If the names/values are chosen well their purpose will be self evident.
Comments are useful for conveying why a particular value was chosen in this particular config file by some person. For example:
# This is temporarily disabled until TICKET-432 is fixed.
# It should then be turned back on.
feature-that-should-usually-be-enabled: falseBut, this is still information that shouldn't be embedded in the config file.
TICKET-432 should say "feature-that-should-usually-be-enabled is set to false while this issue is active. When this is fixed, set it back to true."
They could read through every open ticket to check, but they're only human, and things can be overlooked. If the comment lives right next to option, it's much harder to miss.
I don't see how. If I pick a particular value for a config setting, it's obvious what value was chosen, but there's nothing to suggest why that value was chosen.
Not for your code it wasn't.
A comment like:
# Add 1 to the length of this buffer to work around an off by 1 error in this function in library foo
Can quickly go stale, but sometimes not and could otherwise be accidentally reverted by someone who notices that the buffer is 1 element too long for no apparent reason.
A better comment:
# Add 1 to the length of this buffer to work around an off by 1 error in function foo from library bar (version 1.7.3b circa Nov 1997)
I think TOML strikes a good ballance between simplicity and features for config files. It ends up being easy to read and write.
TOML is really nice for configuration files.
https://github.com/crdoconnor/strictyaml
IMO TOML is syntactically messy, especially when dealing with hierarchical data, and a whole new config format to deal with the fact that YAML has too many features is somewhat unnecessary.
JSON for config is a bad, bad idea - especially if your config will get large.
> Is YAML one of those things that proper professional programmers need but us amateurs can botch our way around?
I really don't understand this attitude. If you already call `json.load(some_string)', there's no difference to change to `yaml.load(some_string)' and go with that. YAML data model is similar to JSON.
JSON is a format mainly for machines, and is somewhat readable for humans. YAML is the reverse: it's mainly for humans, but can be processed by machines.
Actually YAML should be easier to amateurs than to professionals. Pros have tools that deal properly with XML, JSON is a lesser problem.
Spot the typo!
If you think this is stupid because surely everyone uses an editor with automatic scope highlighting etc, I don't think that is the case when you are remotely editing config files via SSH.
A fair bit of my stuff co-exists with other things on the same server, so a per-project deployment system couldn't manage everything without occasional conflicts.
But even if you want to do "manual" changes without Docker, or without a configuration management solution like Puppet etc., I'd do them locally in a git repo or similar and either git pull'ing it or rsyncing it over. Both because it'd mean flexibility in terms of tooling, but also because it makes it easy to actually test it first, or at the very least e.g. syntax check them.
It's nice if it's easy to write - but the real test is read, comprehend, modify.
JSON merges the worst and most redundant parts of C and lisp.