Bosque: Microsoft’s New Programming Language

DZone 's Guide to

Bosque: Microsoft’s New Programming Language

Check out this great introduction to Microsoft's open-source Bosque language as well as hear from its creator.

· Open Source Zone ·
Free Resource

Bosque is described as a programming language that is “simple, obvious, and easy to reason about for both humans and machines.” As a supporter of technology that is “simple”, “obvious” and “easy”, I was interested to see what this meant to a programming language.

To find out more about Microsoft’s new research programming language and the problems it is trying to solve, I spoke with its creator, Mark Marron (@mrkmarron) of Microsoft Research.

Our chat was in-depth, and we touched on a lot of technical aspects. I suggest you listen to the interview in full if you want to know more, and this article summarizes the features of the language.

Pronounced “boss-kay”, Bosque is the Spanish word for forest, which has some pleasant connotations. However, the actual reason for the name “Bosque” is because it was suggested to Mark by an in-house Microsoft naming tool, and he liked it.

What Is Bosque?

Bosque is a programming language that looks to improve developer productivity, increase software quality, and enable a range of new compilers and developer tooling experiences.

Bosque is heavily inspired by TypeScript syntax and types, as well as the semantics of ML and Node/JavaScript. If you have a JavaScript background, Bosque should look familiar and feel pretty natural.

In an attempt to improve upon the structured model of the 70s that most people know and use in many programming languages, Bosque aspires to be a language for modern developers and shuns a lot of the complexity traditionally associated with programming languages. The team wondered if you started from a blank slate, with modern development needs in mind, how would you design a new programming language.

Mark has always had an interest in semantic programming, creating a compiler is a natural extension of this interest. One of the other aims of Bosque is to create a language that is easier for machines to understand, and by reducing some language boilerplate, this is simpler. It also aids the development of developer tooling such as IDEs and IDE plugins; an important area of business for Microsoft.

Installing Bosque

After a year of development, the project was open-sourced to GitHub, but at the moment consists mostly of language specs and reference documentation. You can find a test compiler in the repository that consists of typescript code you can use to compile Bosque (.bsq) code. I assume that in the long run, the compiler may change to a C-style language, but I’m not sure. Included in the reference compiler is a JavaScript library that compiles files to bytecode, so maybe that points to the future.

Language Features

You can find the full language feature list in this document, these are my highlights.

All values in the Bosque language are immutable, following the design trends of many functional languages, and again making creating developer tooling easier.

Typed strings provide a mechanism for providing known structure about the contents of a string into the type in a way that is meaningful to humans and that a type checker can use. For example, to create an American-style zip code type:

function foo(zip: String<Zipcode>, name: String) {...}

var zc: String<Zipcode> = Zipcode#'98052';
var user: String = "Mark";

var zcbad: String<Zipcode> = "9"; //error not a typed string on right side
var zcbad: String<Zipcode> = "98052"; //error still not a typed string on right side
var zcbad: String<Zipcode> = Zipcode#'9'; //error bad format in typed string literal

foo(user, zc) //Type error String not convertible to String<Zipcode>
foo(zc, user) //ok

Bulk algebraic operations support for bulk reads and updates to data values. In other languages, you may use a struct with 3 fields, and need to update 2 of them on a field-by-field basis. With the bulk data operations, you can perform the update as an atomic operation and without manually extracting and copying fields. For example:

var x = {f=1, g=2, h=3};
x->update(f=-1, g=-2); //{f=-1, @g=-2, h=3}

A fundamental concept in a programming language is iterative processing and languages decide whether to implement structures such as filter/map/reduce, or looping constructs. After analyzing a study of all the loops “idioms” found in real-world code members of the Bosque team found that almost every loop a developer would want to write falls into a small number of patterns. With this result in mind, Bosque created a set of high-level iterative processing constructs. There’s a small example of these in the documentation, but keep an eye on this page for details as the team releases them.

A central goal of the Bosque language is to simplify the process of building reliable software. The language provides first-class support for errors and checks and expressing a full range of invariants, sanity-checks, and diagnostic assertions. For example:

entity Foo {
    field x: Int;

    invariant x > 0; //check whenever a Foo is constructed

    method m(y: Int): Int
        requires y >= 0; //precondition
        ensures _return_ > 0; //postcondition
        check this.x - y > 0;   //sanity check - enabled on optimized builds
        assert this.x * y != 0; //diagnostic assert - only for test/debug

        return x * y;

What’s on the Bosque Roadmap?

Mark says the Bosque roadmap has two key priorities right now:

  1. The team believes Bosque eliminates complexity and enables deep understanding & reasoning about source code. To verify this, the team will build sophisticated symbolic analysis engines for the source code. For correctness and to be able to show that an app is bug-free, or that it has bugs.
  2. Perform resource analysis and answer the following questions: What is the Big O complexity of your entire application? How does its runtime scale as a function of your input? What is the maximum memory you can use? Then the team can start building tooling and perform a limit test of just how far they can push automated reasoning.
functional programming, microsoft bosque, open source, programming languages, structural languages

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}