15 ms·
A respected senior engineer once told me "all configuration is code, if it modifies the behaviour of software, it needs to be testable" Yaml is huge unintuitiv
by mataug 5y ago
A respected senior engineer once told me "all configuration is code, if it modifies the behaviour of software, it needs to be testable"
Yaml is huge unintuitive PITA, I recently spent multiple hours figuring out the best way pass CLI arguments to a k8s cronjob via yaml. I only managed to solve the weird error messages after I stumbled upon the stackoverflow post linked in the webpage https://stackoverflow.com/a/21699210 https://stackoverflow.com/a/21699210
> There are NINE (or 63*, depending how you count) different ways to write multi-line strings in YAML.
- eyelidlessness 5y agoI agree that YAML is code and I find it absolutely preposterous that there’s any notion otherwise.
- monsieurbanana 5y agoIs json code, too? Yaml, or json, can be used to describe programming instructions, in which case I could see maybe calling it code. In an informal setting. If you are, for example, writing documentation, please refrain from doing so. But that's entirely situational. A yaml snippet containing my list of groceries is not code. Yaml doesn't have to be classified as code to be testable. "We should have tests for our configuration files" is perfectly reasonable.
- eyelidlessness 5y ago> Is json code, too? I’m amazed this is even a question. Of course it is! It’s explicitly defined as an interchange format. Its only purpose is as code. > In an informal setting. What formal settings are we supposed to be satisfying? > If you are, for example, writing documentation, please refrain from doing so. I respectfully decline this request. > But that's entirely situational. A yaml snippet containing my list of groceries is not code. > Yaml doesn't have to be classified as code to be testable. "We should have tests for our configuration files" is perfectly reasonable. I mean this with kindness and sincerity, if a little incredulity: maybe your definition of code is ambiguous and warrants some clarification. To me, this isn’t a holistic definition but it certainly seems like a relevant starting point: if it has a syntax specification that machines can use, it’s code.
- ChrisLomont 5y ago>Of course it is! It’s explicitly defined as an interchange format. So an INI file is code too? Generally people think of code as being executed and doing some task. Can you use JSON to compute prime numbers?
- reegnz 5y agoA language does not need to be considered Turing complete to be considered code.
- ChrisLomont 5y agoIt needs to perform some computation, right? Or is code now any structured data read by a program?
- olodus 5y agoA python script could be a text doc if you open it in a markdown editor. A yaml file could execute web call if run through a program with a parser. It is all up to the interpreter you give the code too. Your program that takes yaml config is an interpreter, though probably a very limited one and hopefully a safe one (though that needs to be tested / checked for to be more sure of)
- eyelidlessness 5y agoNow? XML has been code for decades.
- emodendroket 5y agoI would guess most would define "code" as being written in a Turing-complete language.
- eyelidlessness 5y agoSo without engaging the ongoing absurd debate about HTML or CSS… can you really say that SVG isn’t code? Forget what “most” would say. In your heart of hearts, can you write <path d="…anything at all"/> and not consider it code? What a disappointing pissing contest.
- funcDropShadow 5y agoI know it is unpopular nowadays, but it really helps understanding between people if we stop redefining terms all the time. So, let's have a look at what a dictionary definition (taken from [1]) of code is: 1. a systematic statement of a body of law 2. a system of principles or rules moral code 3. a. a system of signals or symbols for communication b. a system of symbols (such as letters or numbers) used to represent assigned and often secret meanings c. coded language : a word or phrase chosen in place of another word or phrase in order to communicate an attitude or meaning without stating it explicitly 4. genetic code 5. instructions for a computer Relevant to the discussion here are points 3 and 5. I would argue json, yaml, and xml, would be called code under points 3 as well as 5. [1]: https://www.merriam-webster.com/dictionary/code https://www.merriam-webster.com/dictionary/code
- denton-scratch 5y agoI don't regard Merriam-Webster as authoritative. They are hard-core descriptivists; if they can find an attestation for some usage, however contradictory or plain wrong, they will list it in their lexicon. E.g. "literally": "In a completely accurate way; a story that is basically true even if not literally true". "In effect, virtually; used in an exaggerated way to emphasize a statement or description that is not literally true or possible" So according to M-W, "literally" means the same as "not literally". Merriam-Webster debauch the English language.
- eyelidlessness 5y ago> They are hard-core descriptivists; if they can find an attestation for some usage, however contradictory or plain wrong, they will list it in their lexicon. AKA their dictionary accurately reflects language usage; the opposite being prescriptivism, wherein you reflect the language as you wish it was rather than actual usage.
- funcDropShadow 5y agoInteresting points. Because English is not my mother-tongue, I wasn't aware of perceived quality of that dictionary. I chose Merriam-Webster simply because it was the first hit in my online search. Which English dictionary do you consider better? But, I still find it important to look at definitions that are actually used out there. Some scientific papers I've read just redefined everything to fit their purpose. There is a fine line between making it practically impossible to communicate ideas based on common understanding of terms, and allowing those terms to evolve. Anyway, I am convinced it is a bad idea to try to "feel" or "impulsively answer" the question is json or yaml code. To answer such a question every intelligent person should, IMHO, remember or lookup the relevant definitions and then try to find a conclusive argument why something answers the question. It might also be important to reflect on the quality of the used definitions. Sometimes, definitions should be changed. But changing a definition should always consider many different use-cases and perspectives, otherwise it becomes a single-use tool. And such a definition is not worth it.
- api 5y agoWhy is it used so much? Tooling? Stockholm Syndrome?
- thevagrant 5y agoI think the main idea is to have a config file standard that can be used across different project regardless of the language / tool used? A benefit is that knowing yaml may at least give you the ability to configure the system, even if a project is built using an unfamiliar programming language.
- woodruffw 5y agoFor all of its warts, YAML hits the sweet spot between readability, writability, commentability, and (mostly) intuitive syntax. It's easy to serialize complex objects to, and comes bundled with Ruby's runtime. There are a lot of valid complaints about YAML, but I still reach for it when I really only need a barebones configuration file.
- smt88 5y ago> For all of its warts, YAML hits the sweet spot between readability, writability, commentability, and (mostly) intuitive syntax. Could not disagree more strongly and it seems many others in software agree, based on this comment section and the original article. > It's easy to serialize complex objects to, and comes bundled with Ruby's runtime. I don't know that Ruby support is why it's widely adopted. Ruby is common in some spaces, but not a wildly popular language at all. I honestly think some popular project (maybe Docker Compose or something from HashiCorp?) used it for a config file and then everyone else started doing it too.
- rossy 5y ago>> There are NINE (or 63*, depending how you count) different ways to write multi-line strings in YAML. I hate to be the YAML defender, but I strongly believe that all of YAML's block and flow scalar types are necessary and that YAML's string handling is one of its killer features. Sometimes you need C-style string escaping with "" and sometimes you need verbatim strings with '' (same use-cases as verbatim string literals in programming languages, eg. for regexp.) Sometimes you need collapsed newlines and stripped trailing newlines (writing a description for your blog post in YAML frontmatter) and sometimes you need preserved newlines (embedding other languages like Markdown or Bash in a YAML document.) A language like YAML should let you represent different types of strings in a way that's still human readable.
- mitchellgoffpc 5y agoThe lisp folks are probably wondering why it took us so long to figure out the whole “all configuration is code” thing haha
- emodendroket 5y agoI know there was a vogue to pretend otherwise but there are definitely benefits to not letting your config file execute arbitrary code.
- thewakalix 5y agoWhat do you mean by “arbitrary”? If you don’t want it to access the network or whatever, that’s definitely possible. If you don’t want it to be able to loop forever, though, Turing-incomplete languages like Dhall exist, but that doesn’t stop them from expressing “loop for a trillion years” — but you can always say “we’ll execute this config file for a second and then halt with an error if it isn’t already done”. (You can also pipe an infinite stream into a FIFO and trick your program even if it uses a dumb config language.)
- funcDropShadow 5y agoThe problem with turing-complete config languages, is not that it might take long to evaluate them. The problem is they are hard to modify by programs. A purely data-driven configuration, e.g. an ini-style config file, json, or xml is relatively easy to parse, transform and unparse again. Doing that with a config file written in a Turing-complete language is substantially harder, theoretically even impossible. But in practice most configuration are evaluated from a subset of all programs. A language like Dhall tries to formalize that subset and and thereby enables better processing of such programs.
- zvr 5y agoThe Tcl folks are also wondering the same thing... A "configuration file" is simply a valid script that is executed in a safe interpreter.
- Spivak 5y agoThere are actually infinite ways to represent multiline strings since you can explicitly specify the required indentation. some_key: >4 This text has to be indented by 4 spaces.