by 2mol · 5y ago · 0 comments
- this looks very useful, and
- "parse, don't validate" has proven to me to be a far better approach for all my use-cases.
I guess validation that is language/consumer-agnostic is more useful in a big-tech context? Or maybe the advantage is to put constraints on data that you are sending to a system out of your control?
Keen to hear opinions of people that worked with similar tools.
Another thing I have been working on is a tool to diff, mask, upsert, and transform config or data files in bulk using CUE. https://github.com/hofstadter-io/cuetuls
CUE aims to be turing-incomplete, so no programming. This is based on Marcel's experience writing borgcfg and GCL while at Google.
The quote I really like is "wrap code in data, not data in code"
It has a lot to do with readability, maintainability, and being able to write tooling to work with config or data. Think about building a query tool that can find everything in your config using a particular label. With CUE, it is likely to be a one-liner (once the query proposal is implemented)
I agree, but I don't understand the value of the difference.
> CUE aims to be turing-incomplete, so no programming
You could satisfy this property with an imperative language that lacks recursion, unbounded loops, etc; however, I'm not convinced this property is very useful in practice. I've never worked anywhere where this was a real problem.
> Think about building a query tool that can find everything in your config using a particular label.
In an imperative configuration language, I would just `jq` the generated JSON. At least I think that's analogous to your suggestion?
I kinda like Jsonnet, but it only generates.
Schema that describes data is itself just data and Jsonnet can describe both. While the various Jsonnet compilers do not "know" about any specific meta-schema in which to express schema nor of course any way to apply that schema to data for validation, one can create such systems with Jsonnet as the language and its compilers as a component.
I found CUE because I needed something better than Yaml for generating code, or declarative application code. (https://github.com/hofstadter-io/hof). It was similar to when I found Go and replaced a bunch of C++. I gained way more functionality in my application while shedding more than 50% of my LOC.
This one?
https://github.com/hofstadter-io/cuetils
Do you also make the cuetorials? It was of great help to us a few months ago. Thank you for that.
thanks for the proper link too
For example, we might have a "parsing step" which takes in Bytes (e.g. '[{"email": "chriswarbo@example.com"}]') and outputs a 'NonEmptyList[ContactDetails]' (e.g. 'NonEmptyList(Email(NonEmptyString('c', "hris"), NonEmptyString('e', "xample.com")), Nil)').
Compare this to a "validate" approach, e.g. parsing the bytes to a 'JsonArray', and using a boolean function to check whether it's empty, and whether its entries match the 'contact details' schema. That's problematic, since (a) it leads to "boolean blindness"[3] (the function tells us 'attempting to get those fields should work', whereas the parsing approach actually gives us those fields) and (b) such a boolean function is actually redundant, since deleting all of its call sites (or forgetting to write them to begin with) would give us a program that still compiles and runs (whereas the parsing approach would give a type error: 'Given JsonArray, expected NonEmptyList[ContactDetails]').
CUE's approach seems to be similar to passing JSON values around, and occasionally performing validation checks (if we remeber to); i.e. validating, not parsing.
[0] https://lexi-lambda.github.io/blog/2019/11/05/parse-don-t-va...
[1] http://langsec.org/brucon/ShotgunParsersBruCON.pdf
[2] https://fsharpforfunandprofit.com/posts/designing-with-types...
[3] https://existentialtype.wordpress.com/2011/03/15/boolean-bli...
I'd consider cue to be a config language that by and large tries to make invalid states unrepresentable.