Blockchain Technology and Functional Programming : the Perfect Marriage?
Here's a question. Will blockchain make functional programming more popular?
I recently got interested in functional programming and one thing that struck me was how much more complex and mathematical (and fun!) it is compared to 'normal' (or imperative) programming.
This complexity might be one of the reasons why it is so unpopular, but with this complexity comes important advantages. For instance, it is possible to make mathematical proofs that can help predict and prevent unwanted behaviour from the program.
Remember the DAO hack in 2016? It could have been prevented if it had been programmed with a functional programming language.
There are currently two blockchain platforms that I know of which make use of functional programming.
Current Functional Programming Platforms
The first is Cardano which uses Haskell, a functional programming language based on lambda calculus (see resources below to learn about lambda calculus).
The second is Rchain. Rchain uses Rholang which is a functional language which is based on Rho Calculus which is itself inspired from Pi Calculus (again see resources below. This is very dense stuff).
Rholang is special because it is a concurrent programming language which means it permits multi-threaded computation.
Rchain will use Ethereum's casper protocol. It is not launched yet, but from the looks of it, Rchain will use the Casper protocol before even Ethereum. Which is crazy when you think about it. After all, Casper is the result of research funded by the Ethereum Foundation for the Ethereum blockchain
In fact, Vlad Zamfir, the Ethereum Foundation main researcher on Casper, is on the board of directors of Rchain.
Functional programming languages are a great way of making smart contracts more secure, but they are not the only way.
Making Smart Contracts More Secure Without Functional Programming
Let's look into how to ways to make smart contracts programming more secure without using a functional programming. Let's take Ethereum's Solidity as an example.
When programming in Solidity, it is recommended to perform an audit. Audits, however, do not give absolute guarantee that the code is secure, only that well-educated eyes have examined it and found it secure.
Another way of increasing security is to use standard libraries like OpenZeppelin. These libraries are vetted and tested. Therefore, they should be secure. Of course, what you code in addition to these libraries runs the risk of being unsecure.
The final way to make Solidity smart contracts more secure is to use a programming language that compile to Solidity and which is more secure itself. I'm thinking about SolidityX made by the loom Network. I've never used, or known anyone who actually uses it, but it's there! :smirk:
Conclusion
It's clear that functional programming is a fascinating subject, but can it be more than a niche geek subject? A mere intellectual exercise? Can it be the key to making smart contracts secure and preventing disastrous hacks from occurring in in the future?Are languages like Solidity and the tools it offers, good enough?
Is blockchain technology the perfect partner of functional programming which will propel an otherwise arcane subject to the mainstream? Time will tell what will happen.
Resources
This stuff is fascinating. Sadly, I'm still a noob. Here are resources to learn from made by people smarter than me.
AMAZING lectures about Lambda calculus. Watch this before anything else.
Introduction to Pi Calculus. The rest of the series transitions to Rho Calculus and Rholang
Greg Meredith, the Inventor of Rho Calculus, gives an introduction about Rholang at devcon3
This is a puzzle book made by mathematician Raymond Smullyan. It is filled with brain teasers based on lambda calculus. I've heard it is great and challenging book.
https://www.amazon.com/Mock-Mockingbird-Raymond-Smullyan/dp/0192801422/ref=sr_1_1?ie=UTF8&qid=1528509223&sr=8-1&keywords=to+mock+a+mockingbird
Promotion
Use this referral link and get a 50$ credit for trading fees when using the Covesting exchange.
Covesting is a regulation-compliant exchange that also allows copy trading, a great way of generating passive income by letting professional traders manage your crypto portfolio.