Ballerina (programming language)
In-game article clicks load inline without leaving the challenge.
Ballerina is a general-purpose programming language designed by WSO2 for cloud computing application software. It is free and open-source software released under Apache License 2.
The project began in 2015 by architects from WSO2 as a code-based alternative to the configuration-based integration tools such as enterprise application integration (EAI), enterprise service bus (ESB), and workflow products.
It has various constructs for cloud-native development including support for various data formats and protocols, reliability, distributed transactions, application programming interfaces (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.
Examples
Hello World
The regular Hello World program:
To execute the above program, place the source code in a .bal file and provide the path of the file to the bal run 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:
REST API
GraphQL API
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: ()|boolean|int|float|decimal|string|json[]|map<json>
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 Cloud.toml file. To enable generation of the cloud artifacts, the users can use the cloud build option in the Ballerina.toml file. Use docker to generate just the Docker image and the Dockerfile and use k8s to generate Kubernetes artifacts as well. Minimal sample config TOML files would look something like the following:
Ballerina.toml file:
Cloud.toml file:
Workers
Further reading
- Fernando, Anjana, Warusawithana, Lakmal (2020) , Apress (part of Springer Nature)
External links
- on GitHub