Modern JavaScript at Clause

Clause
Clause
Published in
4 min readOct 9, 2019
A pink flower

— Jolene Langlinais, Full Stack Engineer

As a beautifully complex and adaptive language, JavaScript has many advantages which grow every year. It is no wonder that the language and community is so extremely popular given that it had a large hand in bringing user interface interactivity and responsive web design to the internet. While sometimes complicated, the language proves to be easy to pick up and start, and allows for faster user experiences by being executed client-side.

A large period of time saw JavaScript as problematic and flawed. This was never an issue with the language, but rather the platform it ran on: the browser. This ecosystem was flawed, as there were so many branching factions and chaos. Mozilla was a voice of reason throughout this period, but it was not until Chrome gained enough market share to give incentive to realign people around a standard of how the engine should look and be built. Setting the standard with V8 is how Node.js was subsequently built. As a full programming language with server side execution support, JavaScript now powers modern web applications and scales across the tech stack. Clause chose to rely heavily on this technology due to its community and power.

Approach for Clause

The majority of our work at Clause is in JavaScript, and the majority of the open source software we use from the Accord Project is also built primarily on JavaScript (with some domain specific language mixed in). To architect a reliable tech stack which allows stability and efficiency for handling and executing smart contracts, we at Clause decided JavaScript provides the best set of tools to handle this in a wide array of use cases and environments. We chose JavaScript because of its applicability, diversity of libraries, and ease of use. Syntax within this language is expressive yet simple.

Documentation

At Clause, we wholeheartedly support clarity and thorough documentation. This is showcased in our effort for thorough and robust documentation for both our platform and API specifically.

Because readability is paramount for programming, we consider our documentation as an extension of our pursuit of greater accessibility, as it is humans who will need to interpret the code in order to collaborate. There are great examples of other technology out there (Stripe API and GitHub) that demonstrate that while possibly feeling redundant and overwhelming at first, thorough documentation will allow for easier assimilation and adoption.

If you feel that something in our documentation is unclear or missing, please let us know so we can better improve your experience with us!

Functional and Asynchronous Programming

JavaScript provides us excellent tools to develop in a functional paradigm while handling asynchronous actions. JavaScript is synchronous by default and single threaded; code cannot run in parallel. However, JavaScript was designed to respond to user actions, which are asynchronous in nature. The browser, in which JavaScript lives, provides a set of APIs which handle this functionality. Moreover, Node.js introduces a non-blocking I/O environment to extend this concept to files, network calls, etc.

Asynchronous

Previously, JavaScript relied on promises and callbacks for asynchronous code, which could easily result in Callback Hell. The syntactic sugar built on top of promises (async/ await) provides a much smoother way of handling asynchronous code, but cannot be used with plain callbacks or node callbacks. Now, asynchronous code can be written more like synchronous code. Similar to promises, asyncand awaitare non-blocking.

Moreover, we implement great tools such as Highland.js to introduce streams into the stack and switch between synchronous and asynchronous data sources at will.

Functional

Functions are first class entities in JavaScript, which means they are treated as values and can be used as data. Functions can be referred to from constants and variables, be passed as a parameter to other functions, and be returned as a result of another function. JavaScript got a huge boost in the ability to perform functionally with ECMAScript 2015, now supporting native map, filter, reduce, and more.

In the same vein as asynchronosity, Ramda is an excellent library which provides extra utility to functional programming in JavaScript, making it easier to create code pipelines. All functions are automatically curried, which makes this library extremely useful.

Conclusion

Javascript as a language has so much power, flexibility, and development efficiency, and provides us at Clause with the ability to access many different sectors in our technology stack. This provides for a more collaborative and better experience for our development team. We are excited to be on the forefront of this progressive and innovative programming community.

--

--

Clause
Clause
Editor for

The future of legal contracting. This blog has been relocated to https://blog.clause.io/. Our Medium feed will no longer be updated.