Hacker News new | ask | show | jobs
by specialist 1022 days ago
OC is arguing that Terraform is a suboptimal abstraction for infrastructure-as-code.

I have no dog in this fight. But I do have opinions about DSLs.

The declarative vs imperative, or some hybrid, debate is ongoing with build systems.

James Duncan Davidson, author of Ant build system for Java, famously wrote a post-mortem. Mostly wrt to choice of XML for Ant's syntax and semantics. TLDR: Wheels fall off a declarative model once imperative logic is added.

FWIW, Here's how I think about declarative DSLs. Such as a scenegraph.

You have an exquisite mental model for a scene. It's probably hierarchical.

You attempt to capture that mental model in code. The representation is probably a grove data structure. aka Directed Acyclic Graph where nodes can have key/value pairs for metadata.

You need to serialize that grove. So you pick a suitable syntax. Hopefully something that looks like VRML-97. Basically s-expressions (JSON without the syntactic vinegar), with some way to represent object prototyping (define/use), and don't forget identifiers ("id" field). Bonus points if you include path expressions in your syntax.

That (human readable) serialized grove is the declarative DSL.

In an future perfect world, your mental model, runtime representation, serialization format, AND the real world will be isomorphic.

Not isomorphic? Of course they're isomorphic. Why even mention it?

Funny you should ask.

In the Java world, dom4j for representing XML documents, and most of its progeny, is not isomorphic. Only JDOM2's class hierarchy design actually matches the serialization format. (As of the last time I checked, a few years ago.)

dom4j's mismatch, leaky abstraction, poor design, what have you, begat untold additional labor and heartache. Which is all completely mooted by JDOM2's correct design.

Ensuring correct isomorphism avoids errors in the same way that strong typing and garbage collection do.

To wrap this up...

In my experience, isomorphism is the exception.

I have no idea if Terraform is a good declarative DSL. But I do know that it should be isomorphic with the runtime representation AND the real world. And that should be settled before weaving in imperative functionality.