Currently there are plugins for:
Let’s first install the plugin with VS Code. We will look at the functionality of VS Code in combination with Ballerina from a very high-level perspective not going to any detail level.
Let’s first download VS code. We will do this on the Windows environment but there are also downloads for Mac and Linux. We will not go into details with regards to the installation. The scripts (for among others Linux) and packages / installers work well as far as I tested them.
After downloading VS Code, we install the product using the default values.
We now have Visual Studio Code Setup installed.
Adding the plugin for Ballerina
So how do we install the plugin. We saw that it was a file with a vsix extension. When we look at the VS Code development environment we see the possibility to import the plugin for Ballerina.
This takes about a minute or so and then we can verify the installation.
If you get a message that your need to reload to enable it, do so. The message will be shown at the right bottom corner.
Subsequently you need to change the Ballerina.home settings. It seems that windows needs the double backslash in the URL.
You will need to restart VS Code after changing the ballerina.home setting.
Create Hello Yenlo
With Ballerina we cannot only create services but we can also create simple applications. For this blog we are going to create a Hello Yenlo application. So, what do we do? First of all, we are going to click on the iconof VS Code. Since we haven’t opened a folder to store our files in we need to do that first. Click on open folder and select a suitable place to store the files that you’re going to create.
I’ve created the folder ‘training’ to store the files.
When we click on the Explorer icon we can see the folder and next to it the file icon with the green plus. Clicking this icon will create a new file. You first of all enter the name of the file with the suffix of ‘.bal’. Let’s call the file helloyenlo.bal.
The file is now completely empty, and we can start writing our program. Let’s start by typing ‘import ballerina/io;’. As you can see VSCode will try to perform syntax-completion while typing.
This is extremely handy and allows you to quickly define the program without having to look for the possible parameters for annotating your code.
You can either click on it or use Enter to auto-complete. We continue with the main function and within that function the ‘io:println(“Hello Yenlo”);
’ command. CTRL-S will save the file. If everything is okay, you would have the following code on screen. This is of course the equivalent of 10 print “Hello Yenlo” in the old Commodore 64 Basic programming language.
We will not go into the details of programming in Ballerina than more or less show you the way VS Code works as Ballerina development environment.
When you go to the debug option you can turn on the debug window, it is not visible per default. Click on the terminal option and you find yourself in the Windows PowerShell. Here we can start Ballerina and run helloyenlo.bal.
The response is the program is of course:
PS C:Ballerina-platform-0.970.1training> Ballerina run helloyenlo.bal
Hello Yenlo
PS C:Ballerina-platform-0.970.1training>
Compile
Ballerina can run both the source-bal files as well as run Ballerina-compiled code. So, let’s try to compile the same file that we just created. In this case we need to type in Ballerina build helloyenlo.bal
in the Powershell window.
We cannot run the same file but need to an X at the end to signify the compiled version. You will not be surprised if the outcome is actually the same for running both the source and compiled versions of our hello Yenlo program.
Diagram
Ballerina uses sequence diagrams to visualize the programming logic and from the Composer tool (start composer from the Ballerina/bin) it allows you to create high level structures like a main function, a function. Like with WSO2 Developer Studio it allows you to define the global flow of the program but the specific criteria in for instance an IF statement is done in the source code.
The Hello Yenlo Diagram looks something like this.
The support in VS Code for creating sequence diagrams is not yet there. The same goes for Intellij Idea where this functionality limited, we can view of the sequence diagram but not edit it with Intellij.
Docerina
Docerina is the documentation tool that comes with Ballerina out-of-the-box. It will take all your Ballerina source code and generate documentation from it. All of the documentation you see online on Ballerina.io is generated with Docerina for instance. Apart from the documentation of the code you can also include your comments and documentation in order to be included in the documentation itself. The command for Docerina is ‘ballerina doc
’ followed by the name of the Ballerina file in the package name depending on what you like.
This is the sort of documentation that is generated using Ballerina’s built-in document generation tool (Docerina). We will dedicate a blog on the functionality of Docerina.
Testerina
Ballerina has a built-in test framework called Testerina. It uses a test package that needs to be imported in Ballerina test source files and the recommendation from WSO2 is to have a structured test model that is aligned with standard pepper cement, this means you have a separate directory in a ballerina package which allows you to isolate the source from the tests and therefore keep it clearer.
We will cover this tool in a later blog in more detail.
Conclusion
You have the possibility to use the standard composer that is out of the box included in the ballerina environment and runs completely in the browser on port 9091.This means that you create ballerina programs without having to install any additional development software locally. The second option is to use VS Code or IntelliJ with a plugin for Ballerina. These plugins are tied to the version of Ballerina and especially in the months before the 1.0 release could mean regular updates as far as the plugins goes. The functionality of VS Code is not the same as composer, e.g. the visual editing capability needs to be looked in to by WSO2.
What IntelliJ offers and to what extent it is a viable alternative will be covered in a separate blog.
What should you do when you want to test out Ballerina? I suggest to just download the latest stable version (0.975.0) at this moment from the download page and play around with the functionality. There is no direct need to switch to the VS Code or IntelliJ plugin just now, unless that is your favorite development environment.