Maybe a silly question, but if you have a programming language available why can’t you buld a native structure, validate it and serialise it to YAML/JSON/whatever completely skipping templating part?
So long as you use only string keys you can completely replace YAML with JSON (i.e. you can write JSON to a YAML file). Just make a .d.ts for your config schema and you're done.<p>Avoiding YAML is this way has saved my sanity on more than one occasion.
The most useful construct I am aware of that I wish became more popular in backend languages is strongly typed tree literals. (Introduced by Meta in Hack as "XHP")<p>Consider this pseudocode expression:<p>:Div{Hello :Span(style='bold'){world}} # expression type: HTMLDOMNode.Div<p>This is immensely powerful and saves a ton of time/bugs especially when compared to the alternative of string interpolation.<p>I know somebody once did XHP on Python, but regrettably this work was abandoned.
I read this.<p>I read it if only to glean why anyone would do this. I learned nothing of the sort of person who would use Javascript to structure a YAML config.<p>10 years ago this article would have been "Used PHP for structured YAML config" and there would have been a minor riot of people poking fun at the article writer for attempting such sillyness. (And I say this someone who still made my money on PHP 10 years ago).<p>We got soft somewhere along the way and stopped calling out silliness.
I am baffled that we as an industry landed on the concept of „code over configuration“, then went on to choose text based formats like yaml or json and consider it perfectly normal to write these by hand? Or even worse, we use bastardized in-file template strings to generate hopefully valid YAML in the end.<p>What‘s wrong with configuring our platforms with a <i>real</i>, perfectly working programming language? I think the author had a great point with the schema being disconnected from the configuration file, but he missed the big picture with JSX: JavaScript (or TypeScript) can be perfectly used to emit JSON. JS tooling works with .config.js files.<p>Why must I experience the living hell of helm charts and kubernetes configuration file templates, when I could just emit my config with my favorite programming language?