Home Programming Learn Bosque Programming

Learn Bosque Programming

By Sebastian Kaczmarek , Joel Ibaceta
books-svg-icon Book
eBook $29.99 $20.98
Print $43.99
Subscription $15.99 $10 p/m for three months
$10 p/m for first 3 months. $15.99 p/m after that. Cancel Anytime!
What do you get with a Packt Subscription?
This book & 7000+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook + Subscription?
Download this book in EPUB and PDF formats, plus a monthly download credit
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook?
Download this book in EPUB and PDF formats
Access this title in our online reader
DRM FREE - Read whenever, wherever and however you want
Online reader with customised display settings for better reading experience
What do you get with video?
Download this video in MP4 format
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with video?
Stream this video
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with Audiobook?
Download a zip folder consisting of audio files (in MP3 Format) along with supplementary PDF
What do you get with Exam Trainer?
Flashcards, Mock exams, Exam Tips, Practice Questions
Access these resources with our interactive certification platform
Mobile compatible-Practice whenever, wherever, however you want
BUY NOW $10 p/m for first 3 months. $15.99 p/m after that. Cancel Anytime!
eBook $29.99 $20.98
Print $43.99
Subscription $15.99 $10 p/m for three months
What do you get with a Packt Subscription?
This book & 7000+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook + Subscription?
Download this book in EPUB and PDF formats, plus a monthly download credit
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook?
Download this book in EPUB and PDF formats
Access this title in our online reader
DRM FREE - Read whenever, wherever and however you want
Online reader with customised display settings for better reading experience
What do you get with video?
Download this video in MP4 format
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with video?
Stream this video
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with Audiobook?
Download a zip folder consisting of audio files (in MP3 Format) along with supplementary PDF
What do you get with Exam Trainer?
Flashcards, Mock exams, Exam Tips, Practice Questions
Access these resources with our interactive certification platform
Mobile compatible-Practice whenever, wherever, however you want
  1. Free Chapter
    Chapter 1: Exploring Bosque
About this book
Bosque is a new high-level programming language inspired by the impact of structured programming in the 1970s. It adopts the TypeScript syntax and ML semantics and is designed for writing code that is easy to reason about for humans and machines. With this book, you'll understand how Bosque supports high productivity and cloud-first development by removing sources of accidental complexity and introducing novel features. This short book covers all the language features that you need to know to work with Bosque programming. You'll learn about basic data types, variables, functions, operators, statements, and expressions in Bosque and become familiar with advanced features such as typed strings, bulk algebraic data operations, namespace declarations, and concept and entity declarations. This Bosque book provides a complete language reference for learning to program with Bosque and understanding the regularized programming paradigm. You'll also explore real-world examples that will help you to reinforce the knowledge you've acquired. Additionally, you'll discover more advanced topics such as the Bosque project structure and contributing to the project. By the end of this book, you'll have learned how to configure the Bosque environment and build better and reliable software with this exciting new open-source language.
Publication date:
April 2021
Publisher
Packt
Pages
336
ISBN
9781839211973

 

Chapter 1: Exploring Bosque

The Bosque project was born from Mark Marron's work, where he questioned the accidental complexity that exists in programming languages nowadays. He proposed a new programming language design that eliminated the factors of this complexity in terms of loops, recursion, mutable state, and reference equality, among others, thus resulting in a new paradigm called Regularized Programming.

Bosque has a syntax inspired by TypeScript and adopts semantics from ML and JavaScript, giving rise to a programming language that is easy to write and read.

The simplicity of Bosque allows programmers who decide to adopt Bosque to focus on the core of the problem without worrying about the errors that are caused by the language's accidental complexity. Consequently, they will build more reliable, robust, and predictable programs that have been prepared, by design, to support new trends.

In this chapter, we will cover the basics of what the Bosque project is, as well as some of the theory and motivation behind this project. We will also learn the basics of code intermediate representations (IR). We will learn what they are, why we need them, and what the Bosque approach is. We will also review the problem of accidental complexity and present the concept of regularized programming. Eventually, we will mention where Bosque can be applied.

We will cover the following topics:

  • Identifying the need for another language
  • Learning what intermediate representation is
  • Discovering regularized programming
  • Understanding accidental complexity
  • How the experiment is going so far
  • Bosque applications

By the end of this chapter, you will have knowledge about what Bosque really is and how it works.

 

Identifying the need for another language

Some of the most frequent questions programmers ask during their early learning years are "Why are there so many programming languages?," "Why don't we just use the same language for everything?," and "Why do we keep creating more programming languages?". A useful analogy to explain the diversity of the programming languages that exist today is to imagine programming languages as musical instruments. We have string, wind, and percussion instruments based on different physical principles; in the same way, programming languages are designed based on different architectures and paradigms. However, instruments or programming languages are often used to generate structured and ordered compositions.

We cannot objectively say that a guitar is not appropriate to play the fifth symphony by Beethoven, since we could only give an appreciation for this based on our personal tastes. In the same way, choosing a programming language might not represent preferring syntax or specific expertise.

But it is also true that interpreting some compositions without the appropriate instrument could be an arduous task, and it could mean sacrificing a big part of the piece due to the physical limitations of the instrument's design. A similar scenario unfolds when we're trying to use programming languages to do things that they were not designed to. Often, this could mean putting in a tremendous technical effort, or having to sacrifice performance, productivity, or stability.

In summary, The Four Seasons by Vivaldi can be beautifully played with a violin and maybe not with a drum; similarly, R rather than Lua could be much more suitable and efficient for statistically analyzing information, while Lua is better for extending Nginx servers instead of Ruby. Although we can use the same tools for everything, they will not always be the most appropriate.

Now that we have a better idea about the diversity of programming languages and their suitability for solving some specific types of problems, the following question arises: "Why was Bosque created?" 

When it comes to developing high-level programming languages, one of the main objectives has always been to try to simplify the process of writing code so that it's as close to human language as possible. This allows us to simplify the process of giving instructions to machines using the potential of human reasoning.

But generally, each continuously evolving process implies an increase in complexity, and this complexity may cause mistakes, in the same way that programming languages have been acquiring characteristics that make them complex and prone to causing hard-to-identify errors. By learning from the past and questioning the actual complexity of programming languages, Bosque was born. To solve this and to learn from the past, as inspired by the impact generated by Structural Programming in its day, Bosque was born as a new programming language that eliminates accidental complexity.

As a result, we have a coding process that's more straightforward, predictable, and readable. This allows programmers to focus on the most important stuff or the main program logic, thus improving productivity and making software more reliable.

In the words of Bosque's creator (Mark Marron):

"The Bosque language demonstrates the feasibility of eliminating sources of accidental complexity while retaining the expressivity and performance needs for a practical language, as well as hinting at the opportunity for improved developer productivity and software quality."

Now that we understand why Bosque exists, lets learn how it builds an executable program from high-level source code.

 

Learning what Intermediate Representation is

Nowadays, it's not unusual to find high-level programming languages that use one or more intermediate representations when they're translating source code into binary code or machine code. By doing this, the compilation process can be simplified without us losing the advantages of a high-level language. It opens the path to developing new programming languages and being friendlier with developers and closer to the process of human reasoning. Bosque is no exception.

Let's learn how intermediate representation works by looking at an example.

First, an abstract representation is usually modeled through a graph that describes the program we are compiling through a data structure. This can occur in different ways:

  • An abstract syntax tree (AST)
  • Lineal IR's three-way code or Postfix notation

Let's take a look at the following expression:

5 * a - b

This expression can be expressed using the following AST:

Figure 1.1 – AST graph representation

Figure 1.1 – AST graph representation

If we quickly inspect the graph, we can identify the code's intent through its structure. We could use this abstract representation to generate an intermediate code representation that is more agnostic to the architecture or execution environment. This code is usually a sequential representation of the syntactic tree. Generally, from this abstract representation, an intermediate code representation could be generated. Even though this is more similar to final object code, this code is usually a sequential representation of the syntactic tree, agnostic to the architecture or execution environment.

Here, we can observe the representation in the intermediate code of the previous structure:

t1 = 5 * a 
t2 = b
t3 = t1 - t2

From this intermediate code, and by using a suitable compiler, a final executable binary can be generated, which would be the result of our source code's compilation. Let's look at a more complex example based on a C# snippet. This can be interpreted as follows:

while ( x > y ) {
    if ( x > 0 ) {
        x = x - y;
    }
}

The AST representation of the previous code is as follows:

Figure 1.2 – AST graph representation

Figure 1.2 – AST graph representation

During its interpretation, the C# source code is converted into an intermediate code called IL, representing the original code's intention. However, in this case, it is less understandable at first glance, as shown here:

.locals init ( 
    [0] int32 x, 
    [1] int32 y, 
    [2] bool, 
    [3] bool 
)
IL_0001: ldc.i4.0
IL_0002: stloc.0
IL_0003: ldc.i4.0
IL_0004: stloc.1
// sequence point: hidden
IL_0005: br.s IL_0017
// loop start (head: IL_0017)
    IL_0007: nop
    IL_0008: ldloc.0
    IL_0009: ldc.i4.0
    IL_000a: cgt
    IL_000c: stloc.2
    // sequence point: hidden
    IL_000d: ldloc.2
    IL_000e: brfalse.s IL_0016
    IL_0010: nop
    IL_0011: ldloc.0
...

Later, this intermediate code will be converted into low-level code so that it can be interpreted by the virtual machine that will build the final executable – in this case, .NET Framework. Some additional examples of known intermediate languages are as follows:

  • GNU RTL: This is an intermediate language that's used to support many of the programs in the programming languages found in the GNU Compiler Collection.
  • CIL: This an intermediate language that's used by Microsoft .NET Framework's high-level languages. The final binary code is generated from this representation.
  • C: Even though it wasn't designed as an intermediate language, it's often used as a layer of abstraction for the assembler language, which is why so many languages have adopted it as their intermediate representation.

The advantages of having an intermediate representation include being able to have an intermediate stage of interpretation from the high-level language. In this stage, we can optimize, analyze, or correct the code in the most appropriate way according to the language's design and objectives.

The process of transforming an intermediate representation into native code that results in an executable binary is also called ahead-of-time (AOT) compilation. This has many advantages over the just-in-time (JIT) compilation, generally resulting in a considerable reduction in execution time, resource savings, and shorter startup times.

This is why the Bosque compilation process uses a binary generation tool based on AOT compilation, called ExeGen, whose usage we will explore in more detail in the next chapter. Additionally, the Bosque project has an IR that's been explicitly designed to support the needs of the regularized programming paradigm. It explores how to build intermediate representations so that they include support for symbolic testing, enhanced fuzzing, GC compilation, and API auto-marshaling, among others.

Some of these characteristics that Bosque IR supports are part of the regularized programming paradigm, as we will see next.

 

Discovering regularized programming

One of the main paradigms that is used when stepping away from machine code and representing instructions in high-level expressions is structured programming, which is based on the theory proposed by Böhm-Jacopini during the 1960s, when it was proved that any computable function can be modeled using flow control structures, iteration, and subroutines. It was also asserted that the GO TO instruction could be exempted because its use could lead to the development of spaghetti code. One of the recognized promoters of this idea was E. Dijkstra, who covered it in his paper Go To Statement Considered Harmful.

Following this paradigm, we can design flow charts that represent our program's logic in a more readable fashion. This allows programs to be developed in a more efficient, trustworthy, and legible manner:

Figure 1.3 – Basic structures proposed by the structured programming paradigm

Figure 1.3 – Basic structures proposed by the structured programming paradigm

This paradigm was used by IBM investigator Harlan Mills to develop an indexation system for The New York Times investigation files. It was a great success and gave birth to other companies who had started to adopt the paradigm with enthusiasm.

A new age had arrived and code had become easier to write. The problems at hand could be reduced using a series of structures and diagrams.

Afterward, we saw the imminent arrival of structured design, modularity, and modular programming because of the use of structured programming in more complex settings, thus dividing the problem at hand into more straightforward, smaller problems, and these into other, simpler problems.

This happened in the middle of a golden age for programming that gave birth to more programming languages and more compilers, allowing us to abstract the complexity of the architecture where programs would be executed. IDEs and high-level tools were also that reduced the entry barriers for writing code, taking programs to the many industries that existed at the time.

In the next few years, we saw the uprising of new paradigms such as object-oriented programming (OOP), which represented programs as systems containing entities with properties, behaviors, and states. It intended to apply mental models to problem solving since it was easier to represent the problem in terms of their objects, properties, interactions, and the effects of these interactions.

With OOP, not only mathematical or automation problems could be shaped, but more complex systems could be represented through software, allowing us to reuse mental models or knowledge about the industry and transfer it to an application. However, because of this, we had to worry about remembering and following the state changes of all the objects that had been created during the application's entire life cycle. This implies that even though it's easier to model a real-life system through entities and their interactions, we also have to deal with the language's technical complexity and abstraction issues.

Many years have passed since those days, and we've witnessed the appearance of many other paradigms, the fall of some models, and the revindication of others that seemed like they'd never come back. Technology has also changed – nowadays, problems are more complex, and the internet has taken great relevance in software development. Today, we need to write code much faster to comply with the pace of the changes that are being made, but we also live with what we've inherited from the predecessors of the first designs, architectures, and models, even though we also have many open problems from more than 30 years ago.

Bosque proposed that we go a step further and, just like structured programming, presented a new way to simplify the code writing process through regularized programming. This enhanced the legibility, productivity, and code analysis process, and also helped simplify existing models. This starts with throwing out the source of the mistakes that come with accidental complexity, making it easier to implement formal reasoning models to code. Bosque proposes that we rethink the way in which we build programming languages from a perspective similar to structured programming, with the goal of simplifying the code writing process, thus enhancing its legibility, reliability, and productivity.

This simplicity is a consequence of eliminating the sources of accidental complexity, avoiding the unexpected behavior of our programs, and providing a deterministic perspective for writing code. This new design favors translating formal reasoning models into source code. As a result, we have a new paradigm called "regularized programming."

In the next section, we will understand the advantages of eliminating complexity in programming languages

 

Understanding accidental complexity

Speaking about complexity implies that it's difficult to understand something through simple reasoning. For example, it's hard to predict the result of a program's execution or piece of code that uses various recursion instances, because it's hard to figure out what the result will be without doing a more detailed analysis of the process.

Often, this complexity is inherent to the problem we're trying to solve, which we call essential complexity since we cannot dispense it. A recurrent exercise in mathematics and physics, which has allowed us to make significant advances, is to simplify complex models by eliminating sources of complexity that aren't inherent to the phenomenon we're trying to describe. The problem in software development is that this complexity is an essential part of the problem that's being solved, and it's not so easy to simplify the problem.

Although this complexity is not unique to software, it can be harder to show. For example, if we're constructing a building, which is a structure with plenty of complexity, it's easier to show what part of the structure isn't correctly aligned, a dimension that doesn't comply with the blueprints, or rather that the omissions are pretty obvious. The invisible nature of software means that we need to put in more effort to try and identify the cause of an error in a complex system.

One of the most critical advances in the software industry has been the development of high-level languages that simplify many of the possible causes of error due to complexity. This was achieved by encapsulating problems in abstract structures, hierarchies, and modules, thus allowing programmers to improve their productivity and the comprehension of their written code. This also enabled them to focus on solving the core of the problem and not deal with disk access, memory registers, and precise details surrounding the architecture or the hardware.

The models these languages have been built on carry some sources of complexity that Mark Marron identified in his work, and that Bosque pretends to avoid from the design stage of the new programming language.

Now, let's understand each of these sources of complexity and how Bosque avoids them in its design.

Immutability

Mutability can be more intuitive at a higher level but harder to comprehend in detail, besides making analysis tools harder because it affects the application's state. On the other hand, it implies having to compute logical frames. This could be an arduous task for developers as they must remember the state changes for each entity in their applications.

Mutability is an object trait that allows them to be changed. This concept could be intuitive at first glance because we are used to thinking about transforming things through processes, especially if we have spent a lot of time programming with OOP.

However, this adds an extra level of complexity since we must be aware of all the changes our objects will undergo during the entire execution process.

Additionally, if we consider that our code uses methods and functions that have been provided by external libraries or language helpers, which can change our objects or entities' states, then all the events that modify an object's state become arduous. Consequently, we have less predictable programs.

Let's look at an example to understand this better.

Let's say we have the following code in JavaScript, which describes an object – Charles, in this case:

let person = {
    name: "Charles"
}

Now, let's create a function that assigns a new value to save this person's age:

function setAgeToPerson(person, age) {
    person.age = age;
}

Now we are able to add the age property to person, calling to the function setAgeToPerson():

setAgeToPerson(person, 21);

So, if we query for the properties of person, we will have age and name.

However, let's imagine that a third-party library provides the setAgeToPerson() method. If we had previously assigned a value to age, we could incur an error that could be difficult to identify since we are changing a property with the same name from different places.

This can become a problem if we have many events throughout the code that alter the state or composition of an object, which is even more complex if we consider asynchronous executions or dynamic dispatching.

Due to this and the Bosque philosophy of eliminating sources of complexity, immutability is adopted for all the values throughout the language.

Contrary to mutability, immutability is the concept that objects cannot change state once they've been created. This concept may be familiar to you if you have had experience with functional languages.

Other than improving the predictability of the code and minimizing errors, immutability has many benefits when it's time to understand the code that's been written. The following are some other benefits of immutability:

  • Easy-to-test code
  • Thread-safe by design
  • No invalid states
  • Better encapsulation

In summary, immutability in Bosque allows our applications to be more predictable, secure, and stable, thus allowing us to clearly identify the state of our application through the code that's written. It doesn't let hidden code make unexpected changes.

Loop-free

Loops are part of many junior programmers' training, so it is common to think about them when we're solving problems. However, we may create errors when we use them, which could be avoided.

As we know, when we use loops, we must be careful and correctly use comparison operators such as <= instead of <. This is a frequent mistake, almost like forgetting the semicolon at the end of the line, so we also have to be careful when it comes to creating infinite loops.

On the other hand, loops usually involve an additional effort to try and understand their intent. This is because the programmer must do a mental process, similar to reverse engineering, to get a better idea of the result that will be obtained when they execute a piece of code that contains some nested loops.

Often, the primary intent in loops could be replaced by a higher-order function, which provides better clarity about its intent. Let's look at an example of this. Let's take an array of numbers using JavaScript:

const arrayOfNumbers = [17, -4, 3.2, 8.9, -1.3, 0, Math.PI];

To obtain the sum of all the values of the array in JavaScript, we could write something like this:

let sum = 0;
arrayOfNumbers.forEach((number) => {
  sum += number;
});
console.log(sum);

However, we could use the reduce function to avoid using loops and the need to use mutable data, whose final intention is easier to comprehend:

const sum = arrayOfNumbers.reduce((accumulator, number) => 
accumulator + number 
);
console.log(sum);

In summary, loops could imply that additional effort is needed to read written code and reduce its predictability.

Loop-free coding makes our code declarative instead of imperative, thus simplifying it so that we have a better understanding of its purpose. This also allows us to apply generalized reasoning and better integration to immutable data.

Bosque encourages us to write loop-free code by providing a series of useful methods for working with collections and arrays through algebraic bulk operations.

Indeterminate behaviors

Sometimes, when we compile a program, we don't think we'll encounter any problems. However, when we do execute the code, the result is different from what we had expected. This is called an indeterminate behavior.

Although some algorithms are non-deterministic by design, this implies that, by using the same input, we could expect different results. This could increase the complexity of controlling possible error scenarios.

Some examples of this include attempting to assign values in a matrix beyond the established limits, an unexpected resulting from a math operation due to type inference, or concurrent code execution.

Bosque proposes programs with unique results for the same incoming parameters in order to simplify how the written code is understood. It also helps us avoid errors due to unforeseen execution flows or unexpected behavior.

To achieve this goal, it is necessary to eliminate indeterminate behavior sources such as uninitialized variable support, mutable data, unstable enumeration order, and so on.

Additionally, Bosque proposes eliminating environmental sources of indeterminism such as I/O, random numbers, UUID generation transferring this responsibility to the runtime host, and decoupling it from the language core. Due to this, the host will be responsible for managing the environment's interaction.

That is why Bosque programmers will never see intermittent production failures and will always have more stable and reliable code.

Data invariant violations

The invariance concept guarantees that a property or condition will always comply with predefined conditions, so assumptions can be made without incurring errors. This allows for design-by-contract implementation.

Within a loop, the invariant is represented as the necessary instructions to bring the precondition's value toward the postcondition's fulfillment. For example, if we want to have the sum of numbers in an array, the invariant would be the instructions to accumulate each value's sum. Most programming languages provide operators with access and update elements in arrays/tuples/objects, which changes the state of an object through an imperative multi-step process, making it difficult to track all the changes as a range of mistakes can be made.

Bosque proposes that we use algebraic bulk data operators, which help us focus on the overall intent of the code through algebraic reasoning instead of using individual steps. Let's look at some examples of bulk operations that have been written in Bosque.

We can get the elements located at positions 0 and 2 with the following code:

(@[7 , 8 , 9 ] ) @[0 , 2 ] ;      // @[7, 9] 

Alternatively, we update the value of position 0 by 5 and assign position 3 the value of 1. Consequently, position 2 will be assigned none:

(@[7 , 8] <~(0=5, 3=1);          / @[5, 8, none, 1]

Then, we can add the value 5 at the end:

(@[7 , 8] <+(@[5]);              // @[7, 8, 5]

Don't worry if you don't fully understand the previous code. We'll learn how to build bulk functions in more detail in Chapter 3, Bosque Key features.

Aliasing

At execution time, the same memory position can typically be accessed through different symbolic names. So, when we modify this value through one of these names, the value is changed for all the other names. We call this situation aliasing, which can generate unexpected behaviors and errors that will be difficult to identify.

A practical situation occurs in a buffer overflow scenario, as we know some programming languages allow manual memory management, so if the amount of data in the reserved area (buffer) is not adequately controlled, this additional data will be written in the adjacent area, thus overwriting the original content, which will produce unexpected behavior or a segmentation fault.

The programming languages that we use today having implementations based on particular hardware architectures, for example, how the information is stored in memory through different names or how pointer aliases work, because they could be different in some languages.

On the other hand, using aliases requires that we maintain a specific program execution order to obtain the expected behavior. Write access must be carried out in the same order in which it was written. This implies a big challenge for reordering optimizations.

The immutable nature of values in Bosque means that we only need to use read-only pointers, so analyzing aliases is not necessary, thus simplifying our problem.

 

How the experiment is going so far

Bosque was born from an investigation paper based on the idea of questioning the causes of accidental complexity and proposing a solution that tries to eliminate this from the design of a new language. This paper exposed an interesting setting about how we could improve productivity, have clearer, more legible code, and, in turn, have a smaller margin for committing errors during the development process – all of which can be done by eliminating the causes of complexity.

Later, the language was published as an open source project on GitHub, ready to receive support and community contributions. During this stage, Bosque ceased to be a prototype or experimental language for starting a roadmap to complete its development. It did this by implementing many of the basic characteristics, which turned it into a language for developing applications. However, at the time of writing this book, version 1.0 has not been released yet.

In this process, elements such as commentaries, core libraries, and tools were added that simplify the curve of its adoption by new developers. A series of characteristics were also added for its possible applications. If we're ready to sacrifice things that haven't been implemented yet to adopt regularized programming and to start to change our ways of thinking and solving problems, Bosque is a good choice.

What next?

According to the imminent implementations roadmap that should pop up in the next few months, the following will be coming next:

  • Memoization and singleton pragmas
  • Module/package support
  • Improvements to the core collection libraries
  • Earlier microframeworks, to simplify the development and adoption process
  • N-API native modules so that we can use Bosque via Node.js
  • Integration with the Morphir Project
  • Multiple file compilation

Let's look at some cases where regularized programming and the Bosque approach might be more suitable than other languages.

 

Bosque applications

As we know, we can try to build a house with Lego, but this could be a much more difficult task than doing so with bricks, iron, and mortar. Although we can do something with different tools, some are more appropriate than others. That is why the following question always arises when we explore a new programming language: What are the applications where this language would be more appropriate over others that I already know about? We will try to answer this question by cover a few scenarios, although this does not imply that these are the only things we can do with Bosque.

Cloud-first development

One of the main challenges of new, trending technologies such as serverless applications, microservices architecture, and IoT is reaching interoperability with a minimum computational cost. Nowadays, we must deal with serializing and deserializing messages or the slow response times of cold services starting up.

Bosque includes features such as API types to simplify the development of APIs. Its initialization design allows a zero-cost load for cold startups, in addition to characteristics such as immutability and its deterministic nature, which will enable us to build high-performance and resilient applications for cloud environments.

Automatic verification

One of the advantages of a programming language that allows you to implement models based on formal reasoning is that this can be analyzed by tools that allow us to identify and eliminate errors through verification and validation processes. This improves the reliability of the execution's results. Some of the application settings could be as follows:

  • Cryptographical protocols
  • Implementation of finite state machines
  • A network's mathematical models

Synthesis programming

The deterministic nature of Bosque makes it an ideal candidate for the application of AI for code synthesis from formal specifications. This has been an existing challenge since the first days of AI as a study branch, so this synergy could be fascinating.

 

Summary

Bosque is a new high-level programming language based on a new paradigm called regularized programming, which proposes eliminating accidental complexity sources.

Accidental complexity occurs during the evolutionary process of programming languages as they adapt to new contexts and implement various paradigms.

Eliminating complexity sources allows us to simplify how we write code, allowing developers to focus on the problem's core. This also enables us to write programs that are more predictable, readable, and reliable.

A simple, deterministic, and readable language is suitable for solving the challenges that new technologies bring, such as IoT development, serverless applications, and cloud-first solutions. So, Bosque could be an exciting language for your next project if you consider yourself an early adopter.

Now that you've read this chapter, we understand what the Bosque project is and what the regularized programming paradigm proposes. As a result, you have a better idea of the accidental complexity problem in the programming languages that are available today and are ready to consider Bosque as a new alternative for future projects.

In the next chapter, we will prepare our development environment so that we can start writing programs in Bosque.

 

Questions

  1. What is the Bosque project?
  2. What is the regularized programming paradigm?
  3. What is accidental complexity?
  4. Why should you choose Bosque for your next project?
 

Further reading

Here are some additional reference materials that you may wish to refer to regarding what was covered in this chapter:

  • Dijkstra, E. W. (1968). Go To Statement Considered Harmful. Communications of the ACM, 147-148.
  • Brooks, F. P. (1987). No Silver Bullet – Essence and Accident in Software Engineering. Computer, 10-19.
  • Marron, M. (2019). Regularized Programming with the Bosque Language. Microsoft Research.
  • Jonathan Goldstein, A. A. (2020). A.M.B.R.O.S.I.A: providing performant virtual resiliency for distributed applications. Proceedings of the VLDB Endowment.
  • Harper, R. (2011). Programming in Standard ML. Carnegie Mellon University.
About the Authors
  • Sebastian Kaczmarek

    Sebastian Kaczmarek is an experienced programmer who specializes in web solutions. He holds an engineer’s degree in information technology and is a certified Linux administrator. In the projects he has been a part of, he has worked with many technologies such as JavaScript, Node.js, MongoDB, PHP, MySQL, Java, Hadoop, HBase, and Angular. Sebastian is passionate about JavaScript and Node.js and loves to share his knowledge on Stack Overflow, where he has reached over 177,000 people with his helpful posts. Currently, he’s working as a backend lead at a Polish software company where he is responsible for architecture design and the development of reliable solutions. In his free time, he likes reading books about astronomy and artificial intelligence.

    Browse publications by this author
  • Joel Ibaceta

    Joel Ibaceta is an experienced software engineer who started writing code at an early age. Currently, he has more than 12 years of experience in the technology industry, building software and leading engineering teams throughout South America. He served as the technical leader of MercadoLibre, a Latin American unicorn, NASDAQ-100 company, and he currently works as co-founder and CTO of Kwema Inc., a US-based start-up that develops wearables for employees’ safety. He is a well-known speaker in LatAm technical communities and a hackathon enthusiast who has won some global prizes such as the Facebook Community Challenge.

    Browse publications by this author
Learn Bosque Programming
Unlock this book and the full library FREE for 7 days
Start now