Ballerina programming 

My first impression of Ballerina was that it was an amazing language that would vastly improve the world of SRE. It provides everything we need in the decentralized world: libraries, IDEs, compilers, builders, deployers, documentation, and tools. In Ballerina's first demo, the developers created a REST endpoint listening on a network port, implemented communication with Twitter on their API, and embedded a hello function with the same code file as the main() function of their services, and all in a maximum of 15 minutes. They continued to show more examples, including how to use a circuit breaker with Ballerina in a few very simple steps. 

Ballerina evolved from the Apache Synapse project in 2005. It was developed by WS02 architects in response to integration implementations using existing languages. It is a simple programming language and was released under the Apache License v.2.0

Its syntax and runtime address the hard problems of endpoint integration. It is a Turing complete language, and it enables agility, with fast edit, build, and run cycles. Ballerina code is compiled in services that include transactions, embedded brokers, and gateway runtimes. 

It has the following features:

  • It is a programming language for the network world
  • It is optimized for integration in the distributed world
  • It is very simple to understand and write, like a simple C program with if and else conditions
  • It uses simple syntax with no indentation, unlike languages such as Node.js, Go, Python, or Java, which are not very developer-friendly
  • It has data, network, and security-aware programming inspired by Maven, Go, Java, and Node.js
  • It helps to increase developer's productivity by improving clarity and allowing developers to review code logic at a single glance
  • It has low latency, uses little memory, and has a fast startup time
  • It supports JSON, XML, and tables as a data type
  • It provides connectors for single sign-on authentication. It also provides connectors for BasicAuth, SOAP, AmazonAuth, and OAuth
  • It has deep integration with HTTP, REST, and Swagger
  • It provides client connectors for major web APIs such as Twitter, LinkedIn, Facebook, Gmail, and Lambda functions
  • It has a patent pending
  • It integrates well with Docker
  • It integrates well with Kubernetes and can deploy code using it
  • It can understand your test-case requirements
  • It can understand your package repository requirements and provide a similar model to Go, Node Package Manager (NPM), or Maven dependency management
  • It is available on most widely used IDEs, including Vim, VC, IntelliJ IDEA, and PyCharm
  • It uses the parallel worker concept, where workers are non-blocking, and no functions can lock the execution of other parallel functions defined in the same file

While the preceding list is already very long, there are another couple of important features that are worth highlighting. One of these is the Ballerina composer tool, which is a browser-based tool that can be used to write code and draw sequential diagrams in an innovative way. We can easily switch between the sequence diagram view and the source code view. The composer source code is available in GitHub, so download it and try it in your development work. Another amazing feature is that a single program has a main() function and service endpoints that can listen to any valid network port (from 0 to 65,535) and you can have concurrent processing in a single program. This is the first language that has this kind of innovative feature and that also keeps REST API endpoints in mind.

In this section, we are going to look at the following examples:

  • hello program example
  • A sequential diagram example
  • A simple example with Twitter integration
  • A circuit breaking code example
  • A data type and control logic expression statement
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset