HOME

TheInfoList



OR:

Ballerina is an
open source Open source is source code that is made freely available for possible modification and redistribution. Products include permission to use the source code, design documents, or content of the product. The open-source model is a decentralized sof ...
general-purpose
programming language A programming language is a system of notation for writing computer programs. Most programming languages are text-based formal languages, but they may also be graphical. They are a kind of computer language. The description of a programming ...
designed by
WSO2 WSO2 is an open-source technology provider founded in 2005. It offers an enterprise platform for integrating application programming interfaces (APIs), applications, and web services locally and across the Internet. History WSO2 was founded b ...
for cloud-era application
programmers A computer programmer, sometimes referred to as a software developer, a software engineer, a programmer or a coder, is a person who creates computer programs — often for larger computer software. A programmer is someone who writes/creates ...
. The project started in 2015 by architects from
WSO2 WSO2 is an open-source technology provider founded in 2005. It offers an enterprise platform for integrating application programming interfaces (APIs), applications, and web services locally and across the Internet. History WSO2 was founded b ...
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 A distributed system is a system whose components are located on different computer network, networked computers, which communicate and coordinate their actions by message passing, passing messages to one another from any system. Distributed com ...
. It is easy to write and modify and is suitable for application programmers. The designers, who provided
enterprise integration Enterprise integration is a technical field of enterprise architecture, which is focused on the study of topics such as system interconnection, electronic data interchange, product data exchange and distributed computing environments. It is a c ...
products for over 10 years, used their knowledge of the industry when designing the language, says WSO2 director and Ballerina founder James Clark. Some key concepts in Ballerina include: * The network in the language - Ballerina introduces fundamental, new abstractions of client objects, services, resource functions, and listeners to bring networking into the language. *
Sequence diagram A sequence diagram or system sequence diagram (SSD) shows process interactions arranged in time sequence in the field of software engineering. It depicts the processes involved and the sequence of messages exchanged between the processes needed ...
s for programming - In Ballerina, every program has a corresponding event diagram showing the processes involved and the sequence of messages exchanged between them. * Structural, open-by-default typing - Ballerina has a
statically typed In computer programming, a type system is a logical system comprising a set of rules that assigns a property called a type to every "term" (a word, phrase, or other set of symbols). Usually the terms are various constructs of a computer progra ...
, structural type system that aims to be network data schema friendly. * Moving from code to cloud - Ballerina brings the entire program execution process to the hands of the developer with extensible metadata that gets compiled to runnable programs for all major cloud platforms. * Automated observability - Ballerina incorporates features into the language itself that helps keep track of metrics, logs and tracing.


Examples


Hello World

The regular Hello World program: import ballerina/io; public function main() 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. $ ballerina run hello_world.bal Hello World! The service version of the Hello World program: import ballerina/http; service /greet on new http:Listener(9090) 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: $ curl http://localhost:9090/greet Hello World!


REST API

import ballerina/http; service on new http:Listener(9090) $ curl http://localhost:9090/factorial -d 5 120


GraphQL API

import ballerina/graphql; service /stocks on new graphql:Listener(4000) type StockQuote record ; $ curl -H "Content-type: application/json" -d '' 'http://localhost:4000/stocks'


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 import ballerina/io; public function main() returns error


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: ackagedistribution = "2201.0.0" uild-optionscloud="k8s" Cloud.toml file: ontainer.imagerepository="bal_user" name="greet" tag="v0.1.0"


Workers

import ballerina/http; import ballerina/lang.'int; import ballerina/io; // Workers interact with each other by sending and receiving messages. // Ballerina validates every worker interaction (send and receive) // to avoid deadlocks. public function main() function calculate(string expr) returns int, error


References


Further reading

* Fernando, Anjana, Warusawithana, Lakmal (2020)
Beginning Ballerina Programming
', Apress (part of Springer Nature)


External links

* https://ballerina.io * https://github.com/ballerina-platform/ballerina-lang GitHub repository. {{Programming languages 2017 software Programming languages created in 2017 Scripting languages Dynamically typed programming languages Statically typed programming languages Concurrent programming languages High-level programming languages Free software projects Cross-platform free software