14 ms·
"Lack of programmability" is a feature. Declarative config lets tools statically analyze and transform the config. You can't even figure out what the dependenci
by hombre_fatal 8y ago
"Lack of programmability" is a feature. Declarative config lets tools statically analyze and transform the config. You can't even figure out what the dependencies are going to be for some Gradle projects without executing them. https://stackoverflow.com/questions/51153878/conditional-dependencies-in-gradle https://stackoverflow.com/questions/51153878/conditional-dep... -- The author's programmable example is a classic Bad Idea in my experience.
Also, check out JSON schema and its integration into tools like VSCode. VSCode gives you generalized autocomplete on its own config and known config formats like package.json by pulling in json schema definitions. It works well. Easily a better experience than the executable-program-as-config I learned to hate in the JVM world, and easily better than ad-hoc config like Caddy's.
I have a more practical pitch: make your tool consume json5 as well as json.
Also, it's telling that the author wasn't even willing to stick their neck out enough to pitch a single solution. I guess in the end they realized there are always trade-offs and any alternative would have its own downsides. :) But I'm getting a bit fatigued of these you're-doing-it-wrong posts. They are effortless to write and they're like crack to HN. I can complain about literally everything.
- mavelikara 8y agoJVM world had XML before JSON became the rage.
- dvh 8y ago- parsing xml may cause random random network requests (firewall issues) - xml contain comments, sooner or later someone will try to add data to comments, but you already have the thing for data, the format itself, adding data to comments is stupid - unlike js, in json someone finally said "Enough! There will be only one type of quotes", it makes parser simpler
- darkpuma 8y ago> "- xml contain comments, sooner or later someone will try to add data to comments, but you already have the thing for data, the format itself, adding data to comments is stupid" That's easily the worst argument against comments I've ever heard! Would you argue against comments in code because some jackass could abuse it to insert custom compiler directives or something? Ridiculous. The good comments do easily outweighs any harm some moron is going to do to himself by parsing comments for data. I don't like XML any more than the rest of you, but praising json for not having comments just smacks of sour grapes.
- ChrisSD 8y agoThe intentional lack of comments cements json's position as a (human readable) data interchange format. It's not designed to be anything else. Which is fine. There's nothing wrong with a file format being focused on one goal.
- andrewaylett 8y agoBut you don't _need_ to abuse comments for extra (or meta-) data if you're using XML, you just use a separate namespace. It's definitely the case that XML has features that aren't needed -- or at least, we've survived without them thus far -- but there definitely feels like more than just a smidge of only realising later why some of that complexity was present. See also: npm vs pretty much any other dependency management system.
- sisu2019 8y ago> parsing xml may cause random random network requests (firewall issues) inability to properly use a library should not count against it
- DonHopkins 8y agoJava is a domain specific language for converting XML files into stack dumps.
- stevenpetryk 8y agoWorth mentioning that VS Code also lets you map any filename glob to a JSON schema. [1] 1: https://code.visualstudio.com/docs/languages/json https://code.visualstudio.com/docs/languages/json
- nine_k 8y agoThis totally misses the point of the article :( JSON is a fine format for storing configuration data, and any reasonably structured data. So is XML, protocol buffets, what have you. JSON is a poor format for humans. For a configuration file that an actual human would edit by hand, and read and try to understand later, JSON is a pain. Comments are mostly useless in a machine-generated and machine-consumed file. They are indispensable for humans, because they are a link to what machines are not doing. Nice formatting is useless for a machine-consumed file, because they process a stream of bytes. They are indispensable for humans who recognize text very differently. This boils down to one thing: config files are source code, and need all the amenities that make source code comfortable for humans.
- encoderer 8y agoBeing able to statically analyze and transform configuration is a benefit for humans.
- pier25 8y ago> JSON is a poor format for humans Depends on which kind of humans. For the regular non tech types I agree JSON is poor. A couple of years ago I created a mini spec for a config file so that very low tech paper designers could configure an interactive book. For programmers, JSON works fine in my experience.
- tonyarkles 8y ago> For programmers, JSON works fine in my experience. The author mentions this, and I very strongly agree. What JSON significantly misses is the ability to have comments in your configuration files. I'm not going to hold up the Apache config files as an example of amazing config formats, but... here's an example: https://svn.apache.org/repos/infra/websites/cms/webgui/conf/httpd.conf https://svn.apache.org/repos/infra/websites/cms/webgui/conf/... That's awesome. It describes options that are available and not enabled, and what they do. Right. In. The. File. Comparing that to, say, webpack config... there's a pile of research needed to figure out what options are even available, let alone what they do.
- emn13 8y agoAnybody that wants turing complete programmability in their config file is asking for pain. You can always embed such a language in a string as an escape hatch, so there's no loss of generality in any case, but it's sufficiently painful to encourage simplicity and security. But there exist computation models weaker than turing completeness that are still useful, some of those might be reasonable in a configuration file format. For example, you might want to specify a bunch of things iteratively, or perhaps with some fixed number of temporary variables; that's merely an FSM. Or even simply plain non-iterative logic with parameter passing, which is even easier to reason about and possibly still useful; i.e. re-usable templates without iteration or recursion. I can at least imagine such a configuration file format could be both simple enough for human and machine to reason about, and flexible enough to add value over (say) json. But the devil is in the details; and it's not always immediately obvious what's too complex. In any case, json5 looks like what json should have been from day 1; several of the really critical improvements were common JS practice when json was invented. I'm a little worried about the IdentifierName extension, since that's more than what javascript itself allows (no reserved keywords!). But json5 is also an interoperability problem. The nice thing about a (good) standard is the that if it works someplace, it'll work anywhere. Add json5 into the mix, and that's not the case anymore. Then again, there aren't a huge number of plausible successors to json, so maybe this is the best we can hope for. And it's trivial to down-convert to plain json, which means it's not too bad, I guess? I wish json5 simply worked everywhere ;-).
- whateveracct 8y agoDhall is a good example of a "programmable" configuration file format. It's based on System F, which means you get no-nonsense abstraction (in the LC sense) without any pain. It really helps to be built on something conceptually robust instead of ad-hoc whims. Oh and it has a static type system. Quite nice!
- azernik 8y agoI find HOCON to be a nice minimal extension to JSON - allows config values to reference each other, with some basic string and array functions included, and allows successive files to append to or override existing config values. Fills 90% of what I see people asking for in terms of programmability. https://github.com/lightbend/config/blob/master/HOCON.md#goals--background https://github.com/lightbend/config/blob/master/HOCON.md#goa...
- AnaniasAnanas 8y agoYou can have declarative configs that are programmable, these are not exclusive. > You can't even figure out what the dependencies are going to be for some Gradle projects without executing them This sounds like an issue of Gradle, not of programmable configs in general.
- vbezhenar 8y agoIt's not an issue of Gradle, it's a feature of Gradle. Why would you want to figure out the dependencies without executing script? Programmatic configuration allows e.g. specify some library version once (e.g. springVersion) and use it for 10 dependencies as a variable. And that's a simplest use-case. Full-featured programming language allows for a lot of flexibility. Not every config file needs that, but a config file for a build system definitely needs that. Otherwise your build system becomes too restricted and you must either write your logic in plugins or use another scripts along with your main build tool. Both options are bad. I'm not even sure that build.gradle should be called a config file. It's a build script.
- vorg 8y ago> Why would you want to figure out the dependencies without executing script? Originally, the whole point of using configuration files for builds was to eliminate the programmatic element where you used lots of little scripts to run builds. Config files are easy to read and reason about. > Programmatic configuration allows e.g. specify some library version once (e.g. springVersion) and use it for 10 dependencies as a variable Declarative syntax can also include variables which can't be reassigned to later. Gradle's original marketing message was based around its syntax, i.e. Apache Groovy being easier to read than XML, which is true. But providing the programmatic ability of Groovy as well is a step backwards for configuration best practice, ultimately resulting in an increase in technical debt. Thankfully, almost all the Gradle build scripts out there are simple 20-liners which don't use programmatic logic. Gradle ought to follow the example of Jenkins pipelines, which later provided a Declarative Syntax as an alternative to Groovy to mitigate this very issue.
- AnaniasAnanas 8y ago
- jcelerier 8y ago> "Lack of programmability" is a feature if you ever have a non-programmable config file, then at some point someone will make a turing-complete programming language which goes on top of your tool.
- ihuman 8y agoOr, if it's open source or an interpreted language, they could edit the code of the tool to implement whatever new features they want.
- arp242 8y agoAuthor of the article here; I think this is a complex issue with no single "right" answer. It depend on the context and what you're doing with it. I wrote this after getting annoyed with MediaWiki's new extension format which uses JSON files to set up the extension. What I wanted to do is not include some CSS if a certain plugin is loaded, and that's pretty much impossible to do in a declarative configuration file. Using a JSON file – or any other declarative config – to describe how code works is not a good idea IMHO (although it's probably fine to add basic metadata). The worst case of declarative programming gone wrong that I've seen is probably k8s. I can't really judge your Gradle example, as I've never worked with Gradle (or Java in general). > I'm getting a bit fatigued of these you're-doing-it-wrong posts I agree, and I would rename the article if I hadn't put the full title in the URL (I have since stopped doing that exactly because I wanted to rename this). In my defence, at the time I was annoyed with MediaWiki, PHP, this JSON stuff, and the reasons I even had to work on MediaWiki in the first place (which is a long story involving a lot of drama). That being said, I think using JSON as a human-editable configuration format is, quite frankly, never a good application of the tool. I can't think of any cases where it's the best tool, chiefly due the lack of comments, but also because it's kind of a pain to write. Variants which allow comments – such as JSON5 – are okay, but that's no longer JSON.
- enturn 8y agoLack of comments was the reason I never liked JSON for configuration. JSON5 looks awesome.
- overgard 8y agoWhy does every piece of advice need a counter pitch of a better idea? If I tell you “don’t stick your arm in a wood chipper, even if it’s not running”, I’m hoping you’re not going to be like “well then what should I stick my arm into?!” Presumably he didn’t give prescriptive advice because configuration isn’t one size fits all.
- austincheney 8y ago> "Lack of programmability" is a feature. True... for end users, but absolutely not for other developers. I often see this mentality used as a crutch to baby developers from having to write original code.
- fpoling 8y agoVSCode configs is a bad example to advocate JSON. They embedd a custom DSL into JSON as using JSON structures to express the same things will be too verbose I presume. JSON5 makes things better, but it still requires too much syntactical noise and multi line string values are still not there.
- sqldba 8y agoMaybe it’s meant to be a feature, but instead what happens is you end up with declarative configs absolutely littered with custom metadata and huge and massively complex custom engines to decipher them, where it would have been simpler to include it in the config. They suck.
- sisu2019 8y ago> executable-program-as-config I learned to hate in the JVM world I don't understand how anyone who ever used gradle or even maven and went somewhere else can actually say that Gradle is simply amazing and literally don't know what could be better about it. The link posted is so trivial compared to it's power, it's like criticizing a bullet train for the pattering on the seats.