Live data from Hacker News

Why are we templating YAML?

leebriggs.co.uk

241–250 of 351 posts

Re: Why are we templating YAML?

#241

Earlier quoted context omitted.

>it's as bad or worse than XML for config files XML works very well for config files. It's schema-optional (but is there), well-specified, human-readable, has plethora of supporting technologies (making things like templating easy), and is well supported by every language. At the very least it is way better than JSON.

> human-readable technically yes, practically maybe not so much, especially with e.g. CDATA sections

He means Cantor's XML you barbarian.

Re: Why are we templating YAML?

#242
post #142

Earlier quoted context omitted.

Not sure if it was successful when people call it a hell to maintain and newer simpler alternatives like Parcel is gaining popularity.

I still don't know how to get it to do exactly what I want. There is far too much magic involved, and experience has long demonstrated that magic is bad (Webpack confirms that belief). That being said, the concept of defining a function in, essentially, a config file seems like a step in the right direction. I don't think I'd trust that functionality outside of builds or infra-as-code, though.

What's magic about webpack? The online documentation provides quite a lot of insight into how it all fits together.

It probably only seems like magic because you didn't build a fundamental understanding of how it works before using it. I use some massive webpack configurations and I understand them all quite thoroughly thanks to well-written, modularized configuration files.

Re: Why are we templating YAML?

#243

I've recently settled on typescript object literals for creating complex config files. Adv: - It's still quite declarative. - supports expressions. - supports merging objects using the spread `...` operator. This enables breaking up large configs files into smaller files. - supports type constraints. - serialises to JSON easily.

Same here... just using the same language as the rest application, usually a file with constants or a class/struct/module/whatever. the only reason config files in another language might be required is when you require configuring the application after it is compiled to native binary code. Obviously this doesn't apply to all these applications written in scripting languages. I do wonder how you create type-safe confi…

> I do wonder how you create type-safe config files though

The types help prevent erroneous config declarations.

e.g

```

enum LogLevel {

    Info = "info",
    Debug = "debug"
}

const MyConfig = {

    logOptions: {

        level: LogLevel.Debug

    }
};

```

And since we serialise `MyConfig`, the config has to be transpiled by Typescript.

Re: Why are we templating YAML?

#244

Earlier quoted context omitted.

> Syntactic whitespace kills me. Okay, I'm gonna be the asshole in the room, but how hard is it to just use consistent indentation? I can't count how many times I've heard people complain about significant whitespace in languages. Not only is it not difficult to begin with, but every code editor and IDE will show you where there's a syntax error in your YAML. People are free to dislike YAML, even for its significant…

In the YAML case: It's hard if you don't have editor support and good diagnostics. Not because you're unusually sloppy, but because you make human mistakes and because you don't know the syntax. (YAML syntax is surprisingly complex and poorly documented in the pedagogic sense). Also, the edit-debug cycle is slow with Ansible or YAML-using CI systems, so this is doubly painful. In the Python case it's much better, bec…

Everything is hard when you don't have editor support and good diagnostics. Don't blame YAML because you prefer to use Notepad.exe

However, missing/extra whitespace is not "hard". You would be docked points in an English paper and you should be docked points as a programmer.

So, whitespace aside... Tell me what is easier to edit without built-in syntax support: JSON, or YAML?

If we define "easy" as "how long it takes to complete a task" or "how quickly you can grok the structure of a given block of code", then YAML beats out JSON every time.

Re: Why are we templating YAML?

#245
post #198

My belief is that we've been slowly building up to using general purpose languages, one small step at a time, throughout the infrastructure as code, DevOps, and SRE journeys this past 10 years. INI files, XML, JSON, and YAML aren't sufficiently expressive -- lacking for loops, conditionals, variable references, and any sort of abstraction -- so, of course, we add templates to it. But as the author (IMHO rightfully) p…

This is a great analysis, but it's missing a fundamental point: why do we have a problem with these approximations of a programming language or just using a programming language to template stuff? Because your build then becomes an actual program (i.e. Turing complete) and you have to refactor and maintain it! This is the common problem of using a "programming language as configuration" (e.g. gulp?) Dhall solves exac…

I don't get the problem with using a turing complete language to generate configuration. There's nothing wrong with maintaining and refactoring a program, that's a natural process for any program. If you don't want an infinite loop, don't write one, as you wouldn't in any other program. You can choose as much or as little abstraction as you so wish.

Give me a real language any day over dhall or jsonnet.

Re: Why are we templating YAML?

#246

As others in this thread have said: I ask this question all the time, except s/templating/using/. YAML is insanely over complicated; it's as bad or worse than XML for config files, and it doesn't even have the nice streaming mode. Not to mention that it's a bit of a security nightmare (seriously, who put pointers into the YAML spec?). And, on a more subjective note, YAML is just confusing: between all the significant…

> it's as bad or worse than XML for config files

Let's agree to disagree here. No human should ever write XML. No human should ever be forced to read it.

YAML is very readable and writable if you stay away from the corners. Templating allows you to stay clear of the corners (the 1 char operators that concatenate stuff, b64 stuff and so on).

Re: Why are we templating YAML?

#247
post #161
post #157

Earlier quoted context omitted.

God, I hate programming some times.

Stick with a config format that isn't overengineered and too clever for its own good, like... anything but YAML?

You can always use a subset of YAML (much like we do with JavaScript these days).

Re: Why are we templating YAML?

#248
post #198

My belief is that we've been slowly building up to using general purpose languages, one small step at a time, throughout the infrastructure as code, DevOps, and SRE journeys this past 10 years. INI files, XML, JSON, and YAML aren't sufficiently expressive -- lacking for loops, conditionals, variable references, and any sort of abstraction -- so, of course, we add templates to it. But as the author (IMHO rightfully) p…

This is a great analysis, but it's missing a fundamental point: why do we have a problem with these approximations of a programming language or just using a programming language to template stuff? Because your build then becomes an actual program (i.e. Turing complete) and you have to refactor and maintain it! This is the common problem of using a "programming language as configuration" (e.g. gulp?) Dhall solves exac…

Dhall appears to be expressive enough that I can't see why you wouldn't have to refactor and maintain the Dhall code?

Writing Dhall code look exactly like programming to me, and the programmer must possess the necessary programming skills to produce good Dhall code. A random guy with a text editor will make an equal mess in Dhall as they would with a “real” programming language.

I don't see how the restrictions in Dhall really help much in this regard. Turing completeness feels like a red herring to me.

Re: Why are we templating YAML?

#249
post #198

Earlier quoted context omitted.

This is a great analysis, but it's missing a fundamental point: why do we have a problem with these approximations of a programming language or just using a programming language to template stuff? Because your build then becomes an actual program (i.e. Turing complete) and you have to refactor and maintain it! This is the common problem of using a "programming language as configuration" (e.g. gulp?) Dhall solves exac…

Dhall appears to be expressive enough that I can't see why you wouldn't have to refactor and maintain the Dhall code? Writing Dhall code look exactly like programming to me, and the programmer must possess the necessary programming skills to produce good Dhall code. A random guy with a text editor will make an equal mess in Dhall as they would with a “real” programming language. I don't see how the restrictions in Dh…

Not a user of Dhall, just a fan, but refactoring of Dhall configuration should be extremely easy. You make a change, and your configuration stays the same, which is easy to verify. (Thanks to https://en.wikipedia.org/wiki/Normalization_property_(abstra... )

For TC languages, comparing if two programs (original and refactored) do the same thing is not solvable in general. If the language is not TC then it is more feasible.

Re: Why are we templating YAML?

#250
post #245
post #198

Earlier quoted context omitted.

This is a great analysis, but it's missing a fundamental point: why do we have a problem with these approximations of a programming language or just using a programming language to template stuff? Because your build then becomes an actual program (i.e. Turing complete) and you have to refactor and maintain it! This is the common problem of using a "programming language as configuration" (e.g. gulp?) Dhall solves exac…

I don't get the problem with using a turing complete language to generate configuration. There's nothing wrong with maintaining and refactoring a program, that's a natural process for any program. If you don't want an infinite loop, don't write one, as you wouldn't in any other program. You can choose as much or as little abstraction as you so wish. Give me a real language any day over dhall or jsonnet.

FWIW jsonnet is a "real" language. It's a dynamically typed, lazily evaluated purely functional programming language).
Post reply on HN