Can functional programming support more efficient blockchain infrastructure, who is using it and why?
To say that blockchain technology is fascinating would be an understatement. Hundreds of blockchain projects have already been deployed and hundreds more will launch in the coming months. As companies develop more advanced blockchain infrastructure and applications, a future that revolves around blockchain technology becomes more certain by the day.
Some of the best-known programming languages used in the development of blockchain platforms are object-oriented languages. Languages such as C++, Python, and Ruby have so far dominated the blockchain scene.
If recent developments are anything to go by, functional programming languages are a force to reckon with. They offer blockchain technology unique features that help them exhibit important comparative advantages.
So which functional programming languages are currently being employed for the development of open blockchain protocols? Here are a few examples.
Functional Programming Languages
OCaml is a functional programming language that stood the test of time. It has a static type system, which assists in removing runtime errors. Compared to programs written in C# or Java, programs written in OCaml generally start and run faster, and consume less memory.
Other features of OCaml include first-class lexical closures, parametric polymorphism, exception handling, tail recursion, and pattern matching, in addition to a foreign function interface that supports linking to C primitives. There is also the garbage collector feature for automatic memory management.
Haskell is a purely-functional programming language based on lambda calculus. It has user-friendly syntax, a broad collection of physical libraries and fantastic resources for education and support. These play an important role for reference materials required for prototyping by developers with little knowledge about it.
Haskell also has top-notch tooling, declarative style and static, and strong typing. Such features make Haskell a wonderful option when it comes to building high-performance applications.
Erlang is a functional programming language used for building powerful systems of programs that are distributed over a network of computers. It has been used in the telecommunications industry for more than 30 years and currently 90% of internet traffic goes through Erlang-controlled nodes. As a functional language, it focuses more on the evaluation of expressions. The expressions use functions to obtain basic values.
Erlang started to support multithreading long before any other programming language. It provides garbage collecting, uses a virtual machine, and has pattern matching, which allows for compact and clear programs. Erlang provides an interface to other programming languages like C, C++ and Rust.
Erlang is considered a superior language, especially when it comes to developing back-end systems that require:
- Huge amount of concurrent activity
- Real-time responses
- Non-stop operation and fault tolerance
Now that you know a thing or two about functional programming languages, let’s have a look at what makes them uniquely suited for blockchains.
Advantages of Functional Programming Languages
Generally, functional programming languages do not have mutable variables; once you set a value, it cannot be changed. This makes code behavior more easily predictable and reduces the number of system errors, improving system stability.
- Fault tolerance
Fault tolerance is where a system continues to be in operation, even if a failure occurs. Some functional programming languages, such as Erlang, feature fault tolerance by default.
- Easily parallelized, highly distributed
Functional programming languages enable you to create a highly parallelized and highly distributed systems. Built-in functions for iteration such as map and reduce, come in handy in blockchain development.
While there are many more advantages, let’s dive deeper into more interesting stuff. Have you heard about any blockchains which incorporate functional programming? Keep reading…
Blockchain Protocols Using Functional Programming
Tezos’ is a blockchain project that aims to offer “the world’s first ‘self-amending’ cryptocurrency”. It is a self-governing, decentralized blockchain platform that uses on-chain governance to help it upgrade its protocol over time. Consensus is achieved in an alternative Delegated Proof-of-Stake (DPoS) method, called Liquid Proof-of-Stake.
Tezos is implemented in OCaml, a functional programming language offering speed, an unambiguous syntax and semantic, and an ecosystem making Tezos a good candidate for formal proofs of correctness. Formal verification is where developers are able to mathematically prove the accuracy of their smart contract code.
Cardano is a decentralized, blockchain-based, open source platform that uses Proof-of-Stake mathematical computation called Ouroboros. Ouroboros can generate a consensus through voting by the coin-holders.
The Cardano blockchain is written in Haskell and uses Plutus, a purely functional programming language with strong static types and formal specifications, to define its smart contracts. Plutus’ syntax is fairly Haskell-like, but unlike Haskell, the language is eagerly evaluated.
æternity is a blockchain-based platform that houses smart contracts and decentralized apps. Like Tezos and Cardano the æternity protocol is written in Erlang and its smart contract language — Sophia — is also functional.
Sophia is a programming language part of the ML family. It lacks an arbitrary mutable state but has a limited form of state for each contract instance. It is a robust language that can specify and automatically prove the properties of smart contracts, making it ideal for high-value, system-critical smart contracts.
Apart from Erlang, there are a number of other technological features incorporated in the core protocol that make æternity stand out:
- State Channels — The technology is used to significantly improve scalability of transactions and smart contracts by moving them away from the slower main chain (off-chain). Apart from scalability, an added benefit to state channels is increased privacy, since all transactions or contracts between parties participating in a channel remain private. In addition, since all interactions between the users are private, smart contracts and transactions can be executed in parallel.
- Bitcoin-NG — To improve the usability of mobile decentralized applications, the transactional speed of the main chain must also be increased. At æternity this is achieved with the implementation of Bitcoin-NG, a next-generation consensus protocol that enables much higher transaction speeds while keeping the system decentralized.
- Naming System — An integrated naming system is also part of æternity. Any address, smart contract or oracle can have a human-readable name instead of a string of numbers and letters, as is the case for most other blockchain platforms. This improves user-friendliness and helps smart-contract developers.
- Integrated Oracles — Any AE user can become or use an oracle with a special kind of transaction on the æternity blockchain. Oracles report on real-world events, providing triggers to smart contracts. This improves the utility of smart contracts and realizes their full disruptive potential.
- On-chain Governance — æternity implements a Proof-of-Stake variation to allow AE token users to formally express their opinion on any topic. Any AE user can pose a question or reply to a question by signing a transaction with their AE balance. Delegation is possible. The governance system of æternity resembles a form of liquid democracy, implemented in a blockchain. Voting outcomes signal to the developers what the opinion of the community is on various topics, including fundamental system variables such as block size, block reward or block time. Voting outcomes are not binding, but formally indicative.
- Proof-of-Work Mining — Unlike many new blockchain platforms who implement controversial governance mechanisms with Proof-of-Stake consensus building, æternity relies on the proven Proof-of-Work method.
If you are curious about the team behind æternity — the project has the backing of some of the most experienced developers in the Erlang and blockchain communities. Robert Virding, co-creator of Erlang, Ulf Wiger, one of the most prolific and well-known members of the open-source Erlang community, Sascha Hanse, world-class blockchain developer are all part of the æternity team. On the forefront of the movement is the founder Yanislav Malahov, who is known as the Godfather of Ethereum, since he was involved in the project at its inception.
Functional programming languages are entering the blockchain sphere. Their features could make them uniquely suitable for the development of distributed ledger protocols and smart contracts. Some of the most technologically advanced projects in and out of the blockchain space turn to functional programming for scalability, stability and fault tolerance. Developers with their eyes set on blockchain technology should definitely consider exploring functional programming. It is quite possible that it is the foundation of the most functional smart contract platforms out there. 😉