Ballerina: Data Types

Ayesh Almeida
2 min readMay 9, 2021

Ballerina is an open-source general purpose programming language which is developed by WSO2. In my previous article we discussed on how we could write a Hello World program in Ballerina. Let’s take a closer look at the data types available in Ballerina.

Ballerina has built around the concept of Plain Data.

Plain Data is data that is independent of any specific actions operating on the data. Objects which contain both data and actions to be performed on that data are not considered as plain data.

Plain Data supports deep copy and deep equality. It also supports serialization / de-serialization without coupling.

Overall Ballerina has four data type categories :

  1. Simple Types
  2. Sequence Types
  3. Structural Types
  4. Behavioral Types

In this article we would mainly focus on first three categories.

Simple Types

A Simple Type is a type that is defined as the primitive set of types available in the language. Following is the list of Simple Types available in Ballerina.

Every Simple Type in Ballerina is Plain Data. We could declare a variable of Simple Type in the same way we use in any C / C++ Family Language.

A float is represented using 64-bit IEEE 754–2008 floating-point standard, which converts the decimal fractional values to binary fractional values. In this conversion, it is not possible to always exactly represent the decimal fractional value as it is in binary fractions. Because of this behavior, there can be rounding errors when representing decimal values using the float. To resolve these rounding issues Ballerina has introduced decimal to be used in use-cases which requires accuracy.

Sequence Types

A Sequence is an ordered collection of elements. So, a Sequence Type is a type which has ordered collection of values. Ballerina has support for two Sequence Types.

We could declare a Sequence Type variable just as we would do to a Simple Type variable.

Sequence Types are always Plain Data.

Structural Types

Structural Type is a container/holder of one or more values of either Simple Type or Sequence Type or Behavioral Type.

Structural Types are Plain Data iff the containing types are Plain Data. We could declare Structural Type variable as follows.

Ballerina has a unique type system which makes it stand out among all other programming languages. And with Plain Data concept inbuilt in the type-system Ballerina is quite matching for applications in the integration space.

--

--

Ayesh Almeida

A Tech Enthusiast who wants to build simple solutions for complex problems.