cbor-wg / cddl

The draft leading up to RFC8610
https://tools.ietf.org/html/rfc8610
Other
22 stars 4 forks source link

Comparison to CUE? #30

Open 0Grit opened 2 years ago

0Grit commented 2 years ago

Looks like the discussions feature is not turned on for this repository or I would use it instead of making an issue.

Trying to gather my bearings as I get back up to speed on modeling

I'm curious how those working on CDDL might compare CDDL to CUE. https://cuelang.org/docs/usecases/datadef/

@mjkoster @beriberikix @vitprajzler @alvarowolfx

beriberikix commented 2 years ago

The CUE docs do a bit of a comparison:

The Concise Data Definition Language (CDDL) is used to define the structure of CBOR or JSON data. CDDL shares many of the same constructs from CUE, including disjunctions, embedding, optional fields, and definitions.

CDDL, however, has no value lattice and does not define mathematical properties of its data. There several other aspects in CDDL that contradict the use of a value lattice or make it harder to do so. Overall this restricts the expressiveness of CDDL compared to CUE while complicating the ability to combine constraints on types from multiple sources.

Unlike OpenAPI, CDDL is a domain-specific language (DSL). It needs a specific interpreter. It also has some non-trivial aspects to its evaluation, making it much harder than OpenAPI to implement.

cabo commented 2 years ago

I don’t think it is easy to compare CUE and CDDL, because CUE is trying to solve a different set of problems.

When focusing on data definition (and validation), I’d say:

The Concise Data Definition Language (CDDL) is used to define the structure of CBOR or JSON data. CDDL shares many of the same constructs from CUE, including disjunctions, embedding, optional fields, and definitions.

Right. Fundamentally, they share the concept that values are types, which makes them rather similar in many ways.

CDDL, however, has no value lattice and does not define mathematical properties of its data.

The value lattice concept appears to be CUE’s concept for computing constraints from combining pieces of CUE. CDDL does not define how to do that, as this is usually not a necessary computation when using CDDL (one simply combines the constraints). However, the underlying properties are relatively easy to derive from the CDDL specification. So I’d like to see an example where there is a practical difference.

There several other aspects in CDDL that contradict the use of a value lattice or make it harder to do so.

Even if value lattices are not that relevant for CDDL, it would be useful to have a writeup for those.

Overall this restricts the expressiveness of CDDL compared to CUE while complicating the ability to combine constraints on types from multiple sources.

Again, this seems to be based on a way of using CUE that is not typical for the way CDDL is used.

… Now the discussion is switching from CUE to json-schema.org (which is the relevant part of OpenAPI):

Unlike OpenAPI, CDDL is a domain-specific language (DSL).

Of course, that’s one of the main points.

It needs a specific interpreter.

Not sure what this means (beyond “someone has to implement CDDL so we have a CDDL implementation”).

It also has some non-trivial aspects to its evaluation, making it much harder than OpenAPI to implement.

I’m not sure the implementers would agree… (Yes, you have to write a parser; there goes an afternoon. Apparently hasn’t hurt CUE...)

Of course, specific features of CDDL (such as the recent integration of ABNF) require additional effort, but then these features are there for a reason.

Grüße, Carsten

beriberikix commented 2 years ago

Thanks the detailed response, Carsten! Do you see any opportunities or advantages to use CUE & CDDL together? For example, CUE integrates with Protocol Buffer, so would integrating CDDL in a similar create value?