- Home
- >
- Software Development
- >
- Why Should You Program with Ballerina? – InApps Technology 2022
Why Should You Program with Ballerina? – InApps Technology is an article under the topic Software Development Many of you are most interested in today !! Today, let’s InApps.net learn Why Should You Program with Ballerina? – InApps Technology in today’s post !
Read more about Why Should You Program with Ballerina? – InApps Technology at Wikipedia
You can find content about Why Should You Program with Ballerina? – InApps Technology from the Wikipedia website
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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | importballerina/http; importballerina/io;
typeCountryrecord { stringcountry; intpopulation; stringcontinent; intcases; intdeaths;
};
// Prints the top 10 countries having the highest case-fatality ratio.
publicfunctionmain() returnserror? { http:ClientdiseaseEp = checknew (“https://disease.sh/v3”); Country[] countries = checkdiseaseEp–>get(“/covid-19/countries”);
jsonsummary = fromvar {country, continent, population, cases, deaths} incountries wherepopulation >= 100000 && deaths >= 100 letdecimalcaseFatalityRatio = <decimal>deaths / <decimal>cases * 100
orderbycaseFatalityRatiodescending limit10 select {country, continent, population, caseFatalityRatio}; io:println(summary);
} |
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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | importballerina/http; importballerinax/googleapis.sheets;
configurablestringgithubPAT = ?; configurablestringrepository = “ballerina-platform/ballerina-lang”; configurablestringsheetsAccessToken = ?; configurablestringspreadSheetId = ?; configurablestringsheetName = “Sheet1”;
typePRrecord { stringurl; stringtitle; stringstate; stringcreated_at; stringupdated_at; };
publicfunctionmain() returnserror? { http:Clientgithub = checknew (“https://api.github.com/repos”); map<string> headers = { “Accept”: “application/vnd.github.v3+json”, “Authorization”: “token “ + githubPAT };
PR[] prs = checkgithub->get(string`/${repository}/pulls`, headers);
sheets:Clientgsheets = checknew ({auth: {token: sheetsAccessToken}}); checkgsheets->appendRowToSheet(spreadSheetId, sheetName, [“Issue”, “Title”, “State”, “Created At”, “Updated At”]);
foreach var {url, title, state, created_at, updated_at} inprs { checkgsheets->appendRowToSheet(spreadSheetId, sheetName, [url, title, state, created_at, updated_at]); } } |
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
Source: InApps.net
Let’s create the next big thing together!
Coming together is a beginning. Keeping together is progress. Working together is success.