Coding in meaningful way(Identifier literal support in ballerina ).

In most of the programming languages, variable names, function names etc cannot have spaces in the middle. So for example, you cannot define variable in java like below

int this is variable = 5;

But ballerina is flexible in this context and can have spaces when defining identifiers(identifier literal). To do that, you need to define the variable names in between two vertical bar “|” characters, so below code blocks are valid in Ballerina

int |this is a variable| = 5;
function |this is a sample function| (){}

When accessing those variables and functions, you need to use same vertical bar syntax. So below is how you can access above variable and invoke above function.

function main(string[] args) {
system:println(|this is a variable|);
|this is a sample function|();
}

Other than that, you can use unicode characters as identifier literals as well. Which means below is a completely valid program in Ballerina.

import ballerina.lang.system;

function main (string[] args) {
system:println(|සිංහල වාක්‍යක් දෙන්න|());
}

function |සිංහල වාක්‍යක් දෙන්න|() (string) {
string |සිංහල වාක්‍යක්| = "සිංහල වාක්‍යක්";
return |සිංහල වාක්‍යක්|;
}

And below is also valid program which is written in Greek

import ballerina.lang.system;

function main (string[] args) {

system:println(|Λάβετε το όνομα|());
}

function |Λάβετε το όνομα|() (string) {
return "sample";
}

U can use unicode characters without vertical bars as well, but in that case, you cannot have spaces in the middle. So for example, below code block is also a valid program in Ballerina(note that there are not spaces between characters).

import ballerina.lang.system;

function main (string[] args) {

system:println(Λάβετετοόνομα());
}

function Λάβετετοόνομα() (string) {
return "sample";
}

This seems pretty cool feature to have so that we can do coding in any language we like and also we can define thing in meaningful ways.

Also note that this identifier literal feature will be available from ballerina version 0.87 onwards. (Unicode support in identifiers is already there in current release 0.86 as well)

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store