Ballerina (programming language)

Ballerina is an open source general-purpose programming language designed by WSO2 for cloud-era application programmers.

The project started in 2015 by architects from WSO2 as a code-based alternative to the configuration-based integration tools such as EAI, ESB, and workflow products.

It has various constructs geared toward cloud-native development including support for various data formats and protocols, reliability, distributed transactions, APIs, and event streams.

History
Ballerina was first publicly announced in 2017 and version 1.0 was released on September 10, 2019.

Design
Ballerina is a general-purpose language with a familiar syntax along with a direct graphical representation of the code in the form of sequence diagrams. It has fundamental abstractions designed to make integration problems easier to program. Ballerina was designed by WSO2 to improve productivity for application developers that have to work with distributed computing. It is easy to write and modify and is suitable for application programmers.

The designers, who provided enterprise integration products for over 10 years, used their knowledge of the industry when designing the language, says WSO2 director and Ballerina founder James Clark.

Hello World
The regular Hello World program:

To execute the above program, place the source code in a  file and provide the path of the file to the   command.

The service version of the Hello World program:

Services are executed in the same manner, except they don't terminate like regular programs do. Once the service is up and running, one can use an HTTP client to invoke the service. For example, the above service can be invoked using the following cURL command:

Sequence diagram
The generated sequence diagram is a canonical representation of the source code. The two representations can be used interchangeably. The diagram support is provided through the Ballerina VS Code plugin. The following are a couple of such generated sequence diagrams, compared with its associated code.

A sample program for retrieving and processing COVID-19 data:



A sample program for creating a report out of pull request data retrieved from GitHub:



JSON support
The language provides support for working with JSON values. The builtin type `json` is defined as the following union:

Code to cloud
Docker and Kubernetes artifacts required for deploying the code to the cloud can be generated when building the code. Values required for these artifacts are derived from the code. Additionally, one can override these values as well using the  file. To enable generation of the cloud artifacts, the users can use the  build option in the   file. Use  to generate just the Docker image and the Dockerfile and use   to generate Kubernetes artifacts as well. Minimal sample config TOML files would look something like the following:

file:

file: