Cloud Native Ecosystem / Software Development / Sponsored / Contributed

Why Should You Program with Ballerina?

21 Apr 2022 8:05am, by

The modern-day application, whether it’s a web or mobile app, typically has a frontend and a backend. There are many frontend application technologies out there, and the backend often consists of one or hundreds of APIs, depending on the complexity of the application.

Vishva Ahangama
Vishva is a senior lead marketing officer at WSO2, leading the planning and creation of content-driven experiences for its products. He holds a B.A. in English from Carleton University in Ottawa, Canada.

While it’s possible to write APIs in any programming language, developers face many challenges when creating new APIs and when working with those that exist already. Moreover, enterprise integration is still challenging.

Integration programming practices have become siloed, and developers programming with their preferred integration tool must develop the rest of their applications with another tool or programming language. To add to this, the shift to the cloud means teams must now deploy integration systems in containers and create applications using microservices that are distributed across a wide number of nodes.

Existing programming languages are not particularly adept at understanding these problems and what teams are trying to do. They simply were not built for the cloud. Ballerina, an open source language for cloud native programming and integration, gives the right set of tools and level of abstraction to developers focusing on creating new APIs, new integrations and new logic for network interactions.

With its syntax for developing services and APIs, JSON support and built-in concurrency, the new general availability release Swan Lake can further simplify the way developers build and deploy cloud native apps.

Here are the major reasons why developers should choose Ballerina to program their APIs, integrations and backend logic for their cloud native applications.

Ballerina Is Data and Network Oriented 

With more services in the cloud, almost every enterprise application involves a network call. For developers, this adds the responsibility of working with networked resources in their code. Ballerina comes with a network-friendly type system with powerful features to handle data on the wire.

Ballerina makes it easy to model data and send it back and forth over the network. The language has powerful tools to write, declare, process, query, structure, restructure and navigate data.

With the Power of a Flexible Type System

A programming language’s type system is the foundation for representing data and implementing logic. While the developer must work with networked resources in their code, the programming language itself must aid in this operation. That’s why Ballerina’s network-friendly type system is specialized for this domain.

For example, in typical programming languages, there are standards and protocols to define how to work with data that comes over the wire and bind it to the language (data binding). When data is received, a developer must bind it to a data structure in the language in order to manipulate it.

Ballerina’s type system is capable of describing not just data in memory, but also data on the wire. In particular, a lot of work has been done to align closely with JSON, XML and other formats. When data comes over the wire, a developer can bring it into the language without any artificial, complicated data binding concern, effectively eliminating the data-binding concept from well-known data formats and network data structures.

Ballerina’s type system is primarily structural with added support for nominal typing. This means that type compatibility is identified by considering the structure of the value rather than just relying on the type name. This is different from languages like Java, C++ and C# that have nominal type systems in which it is bound by the name of the actual type.

Sequence Diagrams Model Network Interactions

In Ballerina, every program can be shown as a sequence diagram that illustrates distributed and concurrent interactions automatically. A function in a Ballerina program has equivalent representations both in textual syntax and as a sequence diagram. You can switch between the two views seamlessly. Ballerina’s unique graphical view isn’t something that was tacked on as a gimmick. It’s been designed deeply into the language to provide real insight into a function’s network interactions and its use of concurrency.

While Ballerina has all the general-purpose functionality of a modern programming language, it stands out because it provides language features that make it easier to use, combine and create network services for the cloud. For an in-depth introductory explanation on the language features of Ballerina, we encourage you to watch the video below by Sanjiva Weerawarana, the language’s creator. You can also check out this blog.

Ballerina Swan Lake is available now. As an open source implementation released under the Apache License 2.0, it does not carry any licensing fees and can be freely downloaded at https://ballerina.io/downloads.

Image by Angelica Vaihel from Pixabay