Write Your First Program in Microsoft’s Bosque Language—A Step by Step Approach

Dhananjay Kumar / Monday, April 22, 2019

Microsoft launched a new language called Bosque Language. This is in an experimental phase and designed for writing code that is simple, obvious, and easy to reason about for both humans and machines. This language has TypeScript-like syntax and JavaScript-inspired semantics. 

Some of the main features of the Bosque language are:

  • Improved developer productivity
  • Increased software quality
  • New range of compilers and developer tooling experiences

You can learn more about the Bosque language here.

This article will help you in a step by step manner to configure your system to write your first program in Bosque language. Let’s get started.

Step 1

Download and install LTS version of Node.js from here: https://nodejs.org/en/download/. Once Node.js is installed, run the following command to confirm it was installed.

node –v 

Step 2

After making sure that Node.js is successfully installed, next install TypeScript using npm. To do that run the below command,

npm i typescript -g

You should get a message like the one above upon successful installation of TypeScript.

Step 3

After installing TypeScript, navigate to the Github repository of Bosque language at the below URL,

https://github.com/Microsoft/BosqueLanguage

From here, either download or clone the repository. Once repository is downloaded, unzip it and save at any location of your choice. Change directory to Bosque language master folder and then to folder ref_impl.

In this folder run the following command,

npm install && npm run-script build && npm test

After successfully running the command, you should get output that test passed as shown in the next image,

You have now configured your environment to write your first program in the Bosque language.

Step 4

In this step, we’ll add an extension to Visual Studio Code for syntax highlighting. As of now extensions are not available in the Code Extension Marketplace and we have to manually add them. To do that copy bosque-language-tools folder from bosquelanguage-master folder and copy to C:\Users\username\.vscode\extensions folder. 

Write Your First Program

Create a file with extension .bsq to write a program in it.  I have created a file called hello.bsq

hello.bsq

namespace NSMain;
 
function add2(xIntyInt): Int {
    return x + y;
}
 
entrypoint function main(): Int {
    var result = add2(7, 12);
    return result;
}

A basic Bosque language program should have the following rules:

  • It must have at least one namespace with the name NSMain. Keep in mind that NSMain is keyword.
  • It must have one entrypoint function main. Both entrypoint and main are the keywords.

Update : After writing this, I got a tweet reply from creator of Bosque language that they will give more options to configure namespace and entrypoint in the future .

 In the above program, we have created the add function and called it from the main function. You can run your first Bosque program with below command. I have saved code file with name hello.bsq in C drive.

node bin/test/app_runner.js c:\\hello.bsq

As you see we are getting output, 19 printed.  Congrats, you just compiled your first program in the Bosque language. You can learn about other features of the language here

In further posts, we will discuss other features of the Bosque language.  If you find this post useful, do not forget to check Infragistics award winning product suites here