The Perfect Blockchain Language

Finding the Perfect Programming Language for Developing Blockchain Protocols

Debajyoti (Deb) Ray
Good Audience

--

Blockchain technologies are the roadways and bridges for our current generation, and in building the infrastructure we want to avoid cracks and potholes showing up in the future. Every developer knows the “fail fast and ship early” mantra for consumer apps.

For long-lasting infrastructure, it is crucial to do the hard, time-consuming work up-front to build an impenetrable foundation.

Blockchains build on top of previous transactions. Once a protocol is released into the wild, there are more eyes to discover faults in the code, but also several people willing to exploit them. That is why the time and effort invested earlier on to verify, and ensure that programs have predictable properties pay off in the long run. Good blockchain applications also require an ecosystem to support it. Thus, the programming language on which a blockchain platform is built is one of the major factors in its evaluation.

After systematically learning and evaluating multiple platforms and technologies, I have narrowed the following essential properties of languages to program blockchain infrastructure:

1. Transaction Expressivity

A language should facilitate the breadth of ideas that can be represented and communicated. Earlier and more successful blockchain protocols served the role of digital currencies. With Bitcoin, currency transactions were immutable and verifiable on a public ledger. Smart contract protocols, like Ethereum, opened up the opportunity to encode even more data into the transactions.

Future evolutions of blockchain protocols will enable even richer forms of transaction, and require complex data structures. Beyond just numbers for financial transactions, applications can store rich media files (like MKV for Virtual Reality) for collaborative content creation; detailed industrial designs; or even self-executing AI programs!

2. Safety

The earlier a programming language catches an error, the safer it is to write programs in it. Formal verification methods, pioneered by Tony Hoare, can be used to mathematically prove that a computer program will behave as expected.

So why is formal verification particularly important for blockchain infrastructure protocols?

For standalone programs that run on local machines, computer bugs are annoying (for those who remember Windows Vista). But connected to the internet, they can be exploited to take all the computers in a network down. The Heartbleed vulnerability in OpenSSL, that affected millions of computers worldwide, could have been avoided with formal verification.

Blockchain makes that risk even more substantial. Not only can bugs take down machines, it can wipe out billions of dollars in value, critical health records, and sensitive data. With that much at stake, the time and effort upfront invested in formal verification is absolutely worth it. Fortunately, theorem provers, like Coq and Isabelle, can automate that process, and the code can be written in a formally verifiable programming language.

3. Decentralization

A decentralized network for machines are needed to verify the transactions in a network. If a protocol requires specialized equipment to run effectively, then it pools the power into the hands of a few who have the capital to buy specialized hardware for mining or staking. The compiled bytecode, or virtual machine, therefore needs to be lightweight.

Decentralized open-sourced projects will attract developers with geographical, cultural and language diversity. The easier it is to debug the code, the better it is for collaborative development. Core dumps and memory leaks are much harder to diagnose and debug than stack trace errors from functional languages.

4. Community

The more popular a language is, the more developers there are to contribute to an open-sourced project. However, this is a good to have, rather than a necessity. Without an existing strong community, education becomes more important. Because of the risk and reward calculus, it is better to choose the right language with fewer developers, than to compromise to go after a bigger pool.

Let’s evaluate the major programming languages on those 4 criteria:

Notably, the two most popular languages: Javascript and Python don’t fare so well. However, they are the BEST choices for writing APIs to the core protocol. That is the reason why Ethereum, and most of the other major projects support Javascript and Python APIs.

What language did I choose for blockchain development?

Looking at the pros and cons, I picked OCaml as the language of choice. Haskell was a close second, but the lack of object-orientation limits the type of applications. OCaml, as a programming language, optimizes for Expressivityand Safety. It was founded by researchers at INRIA, although its popularity in the USA is very limited. I encountered it while at graduate school at Caltech, one of the few places that had an ardent community behind it. Also, one of few the times where my knowledge of French helped in understanding the materials :)

Consumer DApp developers gravitate towards platforms like Ethereum and Dfinity because WASM compiles from many popular coding languages. When developers are building complex mission-critical infrastructure DApps in cybersecurity, defense and biotech they’ll choose the platform built specifically for mission-critical DApps. This is where Tezos, built on OCaml, can rule the niche of a platform for blockchain infrastructure projects.

References:

D. Felleisen. “On the expressive power of programming languages”. 1991.

Interview with Tony Hoare. 1980 ACM Turing Award recipient. https://amturing.acm.org/pdf/HoareTuringTranscript.pdf

Connect with the Raven team on Telegram

--

--

Founder & CEO @ RivetAI, building Generative Artificial Intelligence. Investor in AI and Blockchain startups. Caltech PhD.