Google unveils Logica, a new open source logic programming language
Google on Monday announced a new open source logic programming language, called Logica. It is the successor to Google's existing logic language, Yedalog, and is a Datalog-like programming language. The new programming language compiles SQL and can run on Google BigQuery. It is said to be more concise and supports the reusable abstraction feature that SQL lacks, according to a blog post published Monday by Google's open source team. Google is behind many other programming languages such as Go and Dart.
Datalog is a logical query language that sits somewhere between Prolog and the formal relational algebra that underlies SQL. It can be considered either an exceptionally powerful query language or a carefully limited logic programming language. Datalog was created to give database theorists a way to use logic programming, especially through recursive queries.
Yedalog has extended Datalog to be more practical, adding support for concepts such as nested records. It allows programmers to combine parallel data pipelines and computation in a single language. Logica is the successor to Yedalog, which was also one of the programming languages offered by Google.
The new language compiles the logic program into an SQL expression, so that it can be run on BigQuery, Google's advanced SQL engine. Logica also includes experimental support for PostgreSQL and SQLite. According to the Google team, this solution is more concise and "supports the clean, reusable abstraction mechanisms that SQL lacks. It supports modules and imports, it can be used from an interactive Python notebook and it even makes testing your queries natural and easy."
According to Google's announcement on Monday, the new programming language solves the problems faced by SQL by using a mathematical-like syntax for logic rather than just English. The language was designed by talented mathematicians, according to Google, primarily to make it easier for developers to express complex statements, as the mathematical nature better suits the use case rather than plain English. Expressing complex statements is easier and better suited to this purpose than natural language.
"Despite its widespread adoption, SQL is not without its flaws. Constructing statements from long strings of English words (which are often capitalised to retain the COBOL spirit of the 1970s!) can be very verbose - a single query of several hundred lines is common. SQL's main flaw, however, is its very limited support for abstraction.
"Good programming is about creating small, understandable and reusable pieces of logic that can be tested, named and organised into packages that can then be used to build more useful pieces of logic. SQL resists this workflow. While you can encapsulate some repeated computations in views and functions, the syntax and support for these can vary across implementations, notions of packages and imports are generally non-existent, and higher-level constructs (e.g., passing a function to a function) are impossible," the Google open source team wrote.
Logica's big advantage over SQL, according to Google, is its support for abstraction. While SQL supports views and functions to save and reuse subsets of logic, they are limited and vary between SQL implementations. Google's team said of this:
"This inherent resistance to breaking logic down into small pieces is the cause of long, artificial queries, copy-and-pasted pieces of code, and ultimately unmaintained, unstructured SQL code bases (note the irony). To make matters worse, SQL code is rarely tested, as "testing SQL queries" seems rather esoteric to most engineers at best. This is why a number of alternative query languages and libraries have been developed. Of these, systems based on logic programming are perhaps the closest to the limits of SQL.
Logic programming is a declarative programming paradigm in which the program is written as a set of logical instructions. Logic programming was developed in academia from the late 1960s. Prolog and Datalog are the most prominent examples of logic programming languages, and Logica extends the syntax of classical logic programming, most notably with aggregation, hence the name, which means :
Logica = Logic + Aggregation
While SQL works with relations that are equivalent to sets of rows, the equivalent in logic programming is a predicate. This still defines a set of rows, but it is a logical condition that describes the rows of a relationship.
Logica is a declarative programming language that is better suited to data manipulation, according to the announcement. In particular, it aims to bring readability and good engineering practices to database queries, making them easier to read, the Google team says. Logica also allows for the definition and reuse of subqueries and functions. The new open source programming language is licensed under an Apache 2.0 license.
Logica is aimed at engineers, data scientists and other specialists who want to use logic programming syntax to write queries and pipelines to run on BigQuery. Google encourages any developer who already uses logic programming and needs more computing power; or who uses SQL, but is not satisfied with its readability; or who wants to learn logic programming and apply it to Big Data processing, to give it a try.
Source: developpez.com