Questions tagged [ballerina]

For questions about the Ballerina programming language

Ballerina (sometimes referred to as "Ballerina lang" or “Ballerinalang”) is an open-source programming language for the cloud that makes it easier to use, combine, and create network services. Ballerina is designed and developed by WSO2 together with the open-source community.

Type system

Ballerina is a statically typed, concurrent programming language focusing on network interactions and structured data. It has all the general-purpose functionality expected of a modern programming language, but several distinctive aspects make it particularly suitable for its intended purpose.

Ballerina provides language constructs specifically for consuming and delivering network services. Its abstractions and syntax for concurrency and network interaction have been designed to closely correspond with sequence diagrams. This enables a bidirectional mapping for any Ballerina function between its textual representation in the syntax and its graphical representation as a sequence diagram.

Ballerina has a structural type system that is more flexible and allows for looser coupling than traditional statically typed languages. Ballerina's data types are designed to work particularly well with structured data over network interactions by providing first-class support for JSON, XML, tabular data, etc.

Ballerina platform

The Ballerina language has been designed in conjunction with the Ballerina platform, which provides comprehensive support for a module-based software development model, including versioning, dependency management, testing, documentation, building, and sharing.

Code to Cloud

Ballerina Code to Cloud is designed to allow developers to write code without thinking about the deployment platform. This dramatically simplifies the experience of developing and deploying Ballerina code in the cloud.

Ballerina compiler can read configuration files and other first-class cloud-related constructs in the source code and generate artifacts to deploy the code into different clouds. These artifacts can be Dockerfile, Docker image, Kubernetes YAML's, or serverless functions required to deploy the code into different clouds.

Library

The Ballerina language includes a lang library, which provides fundamental operations on the data types defined by the language. The Ballerina platform includes an extensive standard library, which consists of the usual low-level, general-purpose functionality and support for a wide variety of network protocols, interface standards, data formats, authentication/authorization standards, etc. It makes writing secure and resilient distributed applications significantly easier than with other languages.

Ballerina reference documentation

Get started tutorials

Other resources

469 questions
40
votes
4 answers

How does Ballerina differ from other languages?

Ballerina is a general purpose, concurrent and strongly typed programming language with both textual and graphical syntaxes for better integration Is Ballerina an interpreted language? How to build Ballerina programs? Do we need to set…
Abimaran Kugathasan
  • 31,165
  • 11
  • 75
  • 105
7
votes
2 answers

How to implement inheritance in Ballerina

I can see the following description in Ballerina docs regarding type equivalence and inheritance. Ballerina is based on type equivalence, rather than type inheritance. The type system in Ballerina is based on set theory and, therefore, type…
Samitha Chathuranga
  • 1,689
  • 5
  • 30
  • 57
6
votes
3 answers

How do I read an int from command line in Ballerina?

any choice = io:readln("Enter choice 1 - 5: "); I cannot seem to cast the input to an int. Both check and match gives the same error var intChoice = choice; match intChoice { int value => c = value; error err => io:println("error: "…
Samisa
  • 1,012
  • 1
  • 10
  • 19
5
votes
2 answers

Error in passing parameters to sql query in Ballerina

I'm developing a simple ballerina application which retrives the email of a given name(cntname). string sqlString = "SELECT email FROM CONTACTS WHERE Name=?"; // Retrieve employee data by invoking select action defined in ballerina sql client var…
Krishi H
  • 526
  • 8
  • 26
5
votes
1 answer

How to get the index of an object in Ballerina Array?

How can I get the index of an object in a Ballerina array in an efficient way? Is there any inbuilt function to do that?
4
votes
1 answer

Unexpected "compound assignment not allowed with nullable operands" compilation error

In the code below I have correctly narrowed the type of str to string. However the second += compound operator gives me a compilation error: ERROR compound assignment not allowed with nullable operands ERROR operator '+' not defined for 'string?'…
user272735
  • 10,473
  • 9
  • 65
  • 96
4
votes
1 answer

How to Convert JSON to record or map type in Ballerina with JSON key names with spaces

I'm getting a JSON from [1], due to the naming of the keys in the json I was unable to straightaway use either of the 2 approches in hadling JSON in ballerina: Approach 1: Work with json values directly: string s = check j.x.y.z; Approach 2: Work…
Suleka_28
  • 2,761
  • 4
  • 27
  • 43
4
votes
1 answer

ballerina.io SQL LIKE statement

i am currently trying to execute the following SQL statement in ballerina.io against a MariaDB. Plan SQL: select * FROM testDB where test LIKE '%BA%'; I get a result set with all data. ballerina.io: var selectRet = testDB->select("select * FROM…
Martin
  • 65
  • 3
4
votes
1 answer

How to use JWT with Ballerina

I read about JWT and i think i understand how it works, but when things come to ballerina examples i don't understand anything: How do i set the algorithm which i want to use along with JWT and the expiration time? How do i use a custom private…
Under_Ice
  • 147
  • 5
4
votes
1 answer

What does the arrow -> operator do in Ballerina?

I'm new to this language and just started back at it after a few months and have a relatively basic question. I'm having some confusion understanding the arrow -> operator in it. In the examples under Learn Ballerina By Example the basic Hello World…
Rahul P
  • 2,493
  • 2
  • 17
  • 31
4
votes
2 answers

How to convert a string to an int?

According to type conversion example a string to int conversion is made with int.convert(). However in Ballerina 1.0.0 that doesn't work: $ ballerina version Ballerina 1.0.0 Language specification 2019R3 $ cat test.bal public function main() { …
user272735
  • 10,473
  • 9
  • 65
  • 96
4
votes
2 answers

How to create a list of lists in Ballerina?

I need to create a list of lists in Ballerina. In java, I would simply say List>. How do I do this in ballerina? I have the following code. int[][] arr = [[1,2,3], [4,5,6]]; I need to add elements to the 3rd list and it is not…
Dinu94
  • 165
  • 1
  • 12
4
votes
2 answers

Ballerina appending elements to end of an array

How can i append element to end of an array directly other than using following code. string[] array = ["1","2"]; array[lengthof-1] = "3";
Dan.M
  • 71
  • 1
4
votes
2 answers

How to set up http proxy for ballerina?

Is it possible to configure ballerina command to use http proxy when searching for the packages? Doing ballerina search twitter fails with the following error message: Connection to the remote host failed : connection timed out:…
Marko
  • 30,263
  • 18
  • 74
  • 108
4
votes
1 answer

Is Ballerina ready for production?

I find Ballerina a great solution to create an api gateway layer. Is it ready for production? Is someone using it in production? Thanks Gianni
1
2 3
27 28