4 ms·
Scoping to templating json lets the library enforce a really strict contract that you don't get with javascript. For example, * Accessing a missing field is to
by phailhaus 4y ago
Scoping to templating json lets the library enforce a really strict contract that you don't get with javascript. For example,
* Accessing a missing field is totally fine in JavaScript and returns undefined; this is an error in Jsonnet.
* JSonnet guarantees no side-effects, not true of JS.
* When you run a jsonnet file, you have a consistent CLI that handles things like external vars, whereas you'd have to write your own wrapper to do this in JS.
* JSonnet lets you export to multiple different config formats, whereas JS only support JSON really. Again, you'd have to write a wrapper to do this.
* JavaScript would let you return any valid JS object, your wrapper would need to validate.
Like yes, you could write your own JS library to mimic a lot of these behaviors, but the constraints are what make the tool useful. I do wish it had better typing though, so you could more easily inspect the structure of the resulting object.
- graypegg 4y agoIf the constraints are what makes it special, why is it just not very constrained? If you really wanted something totally focused on having multiple configs sharing some base config template, then you wouldn’t be able to do anything other than overwrite specific keys entirely. (json deep merge) Jsonnet seems to let you concat strings, do some math using it’s standard lib (?!), reference other parts of the object etc. I also don’t think “object matches type description” is a niche that JS is lacking, there’s tons of libraries out there to assert that. You’re just trading footguns for different footguns IMO.
- phailhaus 4y agoYep, it's all about them tradeoffs. JS gives you absolute freedom, JSonnet doesn't. JS is easier to debug, JSonnet isn't because it's very declarative.
- spion 4y ago1. can be fixed with typescript 2. can be fixed with Deno - https://deno.land/manual@v1.31.3/basics/permissions https://deno.land/manual@v1.31.3/basics/permissions 3, 4, 5. Why not have that wrapper to solve those? (AFAIK you do need the wrappers for jsonnet too)