4 min read

Inspired by Google’s General Configuration Language (GCL), a team of developers has now come up with a new language called CUE. It is an open-source data validation language, which aims to simplify tasks that involve defining and using data. Its applications include data validation, data templating, configuration, querying, code generation and even scripting.

There are two core aspects of CUE that set it apart from other programming or configuration languages. One, it considers types as values and second, these values are ordered into a lattice, a partially ordered set.

Explaining the concept behind CUE the developers write, “CUE merges the notion of schema and data. The same CUE definition can simultaneously be used for validating data and act as a template to reduce boilerplate. Schema definition is enriched with fine-grained value definitions and default values. At the same time, data can be simplified by removing values implied by such detailed definitions. The merging of these two concepts enables many tasks to be handled in a principled way.”

These two properties account for the various advantages CUE provides:


Advantages of using CUE

Improved typing capabilities

Most configuration languages today focus mainly on reducing boilerplate and provide minimal typing support. CUE offers “expressive yet intuitive and compact” typing capabilities by unifying types and values.

Enhanced readability

It enhances readability by allowing the application of a single definition in one file to values in many other files. So, developers need not open various files to verify validity.

Data validation

You get a straightforward way to define and verify schema in the form of the ‘cue’ command-line tool. You can also use CUE constraints to verify document-oriented databases such as Mongo.

Read also: MongoDB announces new cloud features, beta version of MongoDB Atlas Data Lake and MongoDB Atlas Full-Text Search and more!

Easily validate backward compatibility

With CUE, you can easily verify whether a newer version of the schema is backward compatible with an older one. CUE considers an API backward compatible if it subsumes the older one or if the old one is an instance of the new one.

Allows combining constraints from different sources

CUE is commutative, which means you can combine constraints from various sources such as base template, code, client policies, and that too in any order.

Allows normalization of data definitions

Combining constraints from many resources can also result in a lot of redundancy. CUE’s logical inference engine addresses this by automatically reducing constraints. Its API allows computing and selecting between different normal forms to optimize for a certain representation.

Code generation and extraction

Currently, CUE can extract definitions from Go code and Protobuf definitions. It facilitates the use of existing sources or smoother transition to CUE by allowing the annotation of existing sources with CUE expressions.

Querying data

CUE constraints can be used to find patterns in data. You can perform more elaborate querying by using a ‘find’ or ‘query’ subcommand. You can also query data programmatically using the CUE API.

On a Hacker News discussion about CUE, many developers compared it with Jsonnet, which a data templating language. A user wrote, “It looks like an alternative to Jsonnet which has schema validation & strict types. IMO, Jsonnet syntax is much simpler, it already has integration with IDEs such as VSCode and Intellij and it has enough traction already.

Cue seems like an e2e solution so it’s not only an alternative to Jsonnet, it also removes the need of JSON Schema, OpenAPI, etc. so given that it’s a 5 months old project, still has too much time to evolve and mature.

Another user added, “CUE improves in Jsonnet in primarily two areas, I think: Making composition better (it’s order-independent and therefore consistent), and adding schemas. Both Jsonnet and CUE have their origin in GCL internally at Google. Jsonnet is basically GCL, as I understand it. But CUE is a whole new thing.

Others also praised its features. “When you consider the use of this language within a distributed system it’s pretty freaking brilliant,” a user commented. Another user added, “I feel like that validation feature could theoretically save a lot of people that occasional 1 hour of their time that was wasted because of a typo in a config file leading to a cryptic error message.

Read more about CUE and its concepts in detail, on its official website.

Other news in Programming languages

‘Npm install funding’, an experiment to sustain open-source projects with ads on the CLI terminal faces community backlash

“Rust is the future of systems programming, C is the new Assembly”: Intel principal engineer, Josh Triplett

Kotlin 1.3.50 released with ‘duration and time Measurement’ API preview, Dukat for npm dependencies, and much more!