135 subscribers
join
Rating
Login
Logout

Comparison of The Top 10 Smart Contract Programming Languages in 2021

Crypto Education

Table of Contents

Author: Lee Ting Ting | Founder of The Z Institute

Prerequisites
This article is for developers that are familiar with blockchain and smart contracts. If you are not comfortable with these terminologies, first watch this 5 min video explaining blockchain simply. You can also use this blockchain guide for beginners to reference key terms when you read.

Motivation

As a blockchain developer that has joined the space since 2017, I have experience in coding smart contracts in a number of different programming languages. I believe developers must wonder “Why are there so many smart contract languages and what are their differences? How can I best invest my time to learn one single language and develop on multiple blockchains?” Such questions have long been stuck in my mind. I thus found it worthwhile to survey the top 10 commonly seen languages and publish it as a blog post that outlines their main characteristics to save developers’ lives. :)

Introduction & Outline

The top 10 smart contract languages are selected based on my observation of the prevalence among current developer communities, which includes Solidity, Vyper, Rust, C/C++, Go, C#, Bitcoin Script, Clarity, Move, and Haskell. Among these, some were created specifically for blockchain development (such as Solidity and Vyper), while others were adjusted from existing languages to work with blockchains and smart contracts (such as C and Rust).

Intuitively, when comparing these languages, the key questions are: “What are their differences from a developers’ perspective? What is the design rationale? Is there a need to create new languages for specific blockchains? Why are some languages Turing-incomplete?” Specifically, I summarized seven comparison metrics which will be outlined in the following section. I will also walk through the pros and cons of developing in each language based on my experiences.

The objective of this post is to assist you, as a developer, better understand how to choose among various languages and provide tutorials to get you started.

Quick Table Summary

This table gives you an overview of our comparison summary. Don’t worry if some metrics seem daunting at first glance. We will explain each of them in detail below.


Comparison Metrics

Here is a list of aspects to consider when evaluating smart contract languages:

1. Which blockchains use this language as their smart contract language?
a. The more blockchains a smart contract language supports the better. We all want to learn one language and apply it to a number of blockchains, or port existing projects to other blockchains for a larger audience exposure.

2. Which traditional programming language has the most similar syntax to this language?
a.This information helps you estimate how difficult it is for you to learn this new language. For example, you may find Solidity easier to pick up if you are already a JavaScript developer because of the syntax similarity.

3.Is this language Turing complete? (For more in-depth analysis, refer to this article.)
a.There are pros and cons for a language to be Turing complete. The upside of Turing complete is that it can “solve any problem if it can be coded out”. When Solidity was born in 2015 as a Turing complete smart contract language, it opened up unlimited possibilities of applications to be built harnessing the power of blockchain, while Bitcoin was only regarded as a store of value due to its limited functionalities that can be implemented in Bitcoin script.

However, the downside of Turing complete is that theoretically, “it cannot guarantee how much time it will take to solve the problem.” In the case of the first programmable blockchain, Ethereum, smart contracts are executed serially instead of concurrently. Infinite loops that may block the execution of other smart contracts are thus not possible. Ethereum tackles this issue by adopting “gas limits”, setting an upper bound that caps the maximum complexity of a single execution. Furthermore, research shows that any static analysis of Turing complete languages is either very limited or fundamentally incomplete. Well-constructed Turing incomplete languages will support much more in-depth static analysis, enhancing security.

As a result, Turing “incomplete” has gradually become the new “feature” of some smart contract languages, such as Vyper and Clarity.  


https://twitter.com/TO/status/1408945872365187074?s=20
  1. Does this language support loops?
    a. Usually, functional programming languages do not have loops. Developers must learn the alternative syntax to achieve the same result compared to using loops. For example, in Clarity, we can use `map` or `fold` as a replacement for loops.  
  2. Is it an interpreted language or compiled language? (refer to this article for the differences between interpreted and compiled language)
    a. Interpreted languages minimize the surface area for introducing bugs by removing intermediate compiled representation (such as the EVM byte code for Solidity). Compiler bugs are damaging in blockchains because even if the source code is error-free, the eventual program reaching the blockchain could contain errors (reference). However, interpreted code often runs around 5 to 10 times slower than compiled code (reference) since the interpreter must analyze each statement at runtime. (More on interpreter from Wikipedia) In summary, coding in interpreted languages may be less error-prone but slow.
  3. How trending is this language based on its popularity (evaluated by Github stars)? (data reference)
    a. Note: If the new language is specifically created to build smart contracts, we reference the language that has the most similar syntax with it.
    b. If a language has a lot of Github traffic, it implies that it has a relatively active and well-established community. It implies an even more impressive adoption if the language is popular but relatively new, such as Move.
  4. What is its ranking on the “Most loved programming language” from the Stack Overflow developer’s survey 2020?
    a. If a language is loved by many developers, it is more likely that this language will become more prevalent in the future and have growing community support.
  5. What is the actual Github stars’ count of its own repository?  
    a.This is to give you a quantitative overview of how popular each programming language is. The link to the Github repository is also provided in the above comparison table.

Top 10 Programming Languages

Note that the order below is determined by the prevalence of the language in the blockchain space from my observations.

Solidity


  1. code example 👆
  2. Supported blockchains: Ethereum and EVM compatible chains such as Binance Smart Chain (BSC), Tron, Polygon, xDAI, TomoChain, Cronos (developed by crypto.com), and Quorum.
  3. Syntax similar to: JavaScript
  4. Built with: C++
  5. Turing completeness: True
  6. Support loops: True
  7. Interpreted or compiled language: compiled
  8. Trend ranking based on Github stars: 1
  9. Most loved ranking based on Stack Overflow survey: 10
  10. Description

1.Facts

  1. Initially proposed in 2014, Solidity is an object-oriented and statically-typed programming language for writing smart contracts on Ethereum and EVM (Ethereum Virtual Machine) compatible blockchains. The reason why Solidity was created can be tracked down to why Ethereum needs its own EVM instead of existing VMs. As stated on Stack Overflow, none of the existing VMs satisfied the requirements of Ethereum.  

2.Pros

  1. Historical value as one of the first programmable blockchain’s smart contract languages
  2. Relatively smooth learning curve
  3. Nice writability and readability
  4. Well-established community with sufficient documentation, video / written tutorials, and Stack Overflow Q&As.
  5. Easier to find technical talents that are familiar with this language to work on blockchain projects.
  6. Existing standards are well defined for specific applications, such as ERC20 and ERC721.
  7. Lots of tools available:
    OpenZeppelin offers open-source libraries for secure smart contract development. Developers can inherit and build on top of existing smart contracts that are proved to be secure over time.
    Truffle & Hardhat provides an easy-to-use development environment and testing framework to develop applications.
  8. Well developed ecosystem that leads to better user experiences combined with existing decentralized protocols.  

3.Cons

  1. As a new language, some security pitfalls are yet to be discovered. (Referenced from the Solidity official documentation)
  2. Hard to perform static analysis to avoid bugs in the program since the Turing complete property introduces endless possibilities of how a program might behave.
  3. Developers need to write tests that achieve over 95% of coverage to ensure the soundness of the program.
  4. Significant syntax differences between different versions of Solidity, making codes written in earlier versions harder to be reused.
  5. Developers have less experience with this new language, which leads to a higher probability of bugs.
  6. Lack of built-in overflow and underflow checks for arithmetic operations.

5.References

Solidity Wiki, my own experiences
Links: Github (stars: 11.3K), documentation

Bitcoin script

  1. code example👆
  2. Supported blockchains: Bitcoin
  3. Syntax similar to: Forth
  4. Built with: C++
  5. Turing completeness: False
  6. Support loops: False
  7. Interpreted or compiled language: interpreted
  8. Trend ranking based on Github stars: (No relevant data available)
  9. Most loved ranking based on Stack Overflow survey: (No relevant data available)
  10. Description
  1. Facts
    a.Appeared along with Bitcoin in 2009, Bitcoin Script is simple, stack-based, and Turing incomplete. Instructions are processed sequentially. Data is pushed onto the stack and opcodes (operation codes) are used to perform operations on the items on the stack.
  2. Pros
    a.Historical value as the script of the most prevalent blockchain.
  3. Cons
    a. The opcodes are not easy to learn, write, and read.
    b. Few people actually use this language to build applications. Most of its use cases are for transferring funds with simple logic.
  4. References
    Bitcoin Wiki, my own experiences
    Links: Github (stars: 55.9K), documentation

Vyper

  1. code example👆
  2. Supported blockchains: Ethereum and EVM compatible chains
  3. Syntax similar to: Python
  4. Built with: Python
  5. Turing completeness: False
  6. Support loops: True
  7. Interpreted or compiled language: compiled
  8. Trend ranking based on Github stars: 2
  9. Most loved ranking based on Stack Overflow survey: 3
  10. Description
  1. Facts:
    a. Vyper is a pythonic smart contract language created in 2017 that compiles to EVM bytecode like Solidity. Developers learned from  Solidity’s issues and designed the language to be more simple, secure, and easier to audit. It removes the features that proved to be problematic in Solidity. It is not a replacement for Solidity, but a language to use when they need the highest level of security.
  2. Pros:
    a. Syntax similar to Python
    b. Bounds and overflow checking on array accesses and arithmetic.
    c. Programs written in Vyper will always have a predictable output, while programs written in Solidity will not have a predictable output until it is deployed and executed.
  3. Cons:
    a. Few projects adopt Vyper as their smart contract language. The Number of Vyper contracts vs Solidity contracts on Github is 1000 vs 740K at the time of writing.
    b. Fewer documentation and examples to get started.
  4. References:
    Is Vyper a good alternative to Solidity?, Vyper documentation
    Links: Github (stars: 3.2K), documentation

Rust

  1. code example �(solana), Fungible token contract on NEAR, ERC20 contract on Polkadot
  2. Supported blockchains: Solana, Near, Polkadot
  3. Syntax similar to: (Existing language modified to support smart contracts)
  4. Built with: Rust
  5. Turing completeness: True
  6. Support loops: True
  7. Interpreted or compiled language: compiled
  8. Trend ranking based on Github stars: 13
  9. Most loved ranking based on Stack Overflow survey: 1
  10. Description
  1. Facts
    a. First appeared in 2011, Rust is a language designed for performance and safety, especially safe concurrency. It is syntactically similar to C++ with competent performance but can guarantee memory safety without garbage collection. In addition, it has been voted the "most loved programming language" in the Stack Overflow Developer Survey every year since 2016.
  2. Pros:
    a. Rust is the go-to smart contract language for Solana, the blockchain with one of the highest TPS (transactions per second) to date (real time TPS).
    b. Competent performance like C/C++
    c. Bugs (except logical ones) can be eliminated during the program's compilation.
    d. Inbuilt dependency manager called Cargo.
    e. Rust developers are often more experienced, leading to fewer bugs in the applications developed.
    f. Rust programs can be executed on embedded systems.
  3. Cons:
    a. Program compilation can be time-consuming (above 10 minutes for large projects)
    b. The syntax is more complicated to learn, write, and read.
    c. Fewer examples for Rust smart contracts.
  4. References:
    Golang vs Rust, Rust Wiki, my own experiences
    Links: Github (stars: 56.8K), documentation for Solana, documentation for Near, documentation for Polkadot

C/C++

  1. code example, Logging contract on Solana
  2. Supported blockchains: EOS, Solana
  3. Syntax similar to: (Existing language modified to support smart contracts)
  4. Built with: C / C++
  5. Turing completeness: True
  6. Support loops: True
  7. Interpreted or compiled language: compiled
  8. Trend ranking based on Github stars: 7
  9. Most loved ranking based on Stack Overflow survey: 18
  10. Description
  1. Facts:
    a.First appeared in 1972, C is a procedural programming language with a static type system. It was initially developed to construct utilities running on Unix, and was applied to re-implementing the kernel of the Unix operating system.
  2. Pros:
    a. C/C++ is in the compulsory syllabus of all students with a computer science major. More developers are familiar with its syntax.
    b. C is a portable language that can be run on multiple machines.
    c. Rich libraries for efficient algorithms and data structures.
    d. Well-established community with sufficient documentation, video / written tutorials, and Stack Overflow Q&As.
  3. Cons:
    a. Compared to Rust, it is hard to write memory-safe code.
    b. Pointers in C/C++ are a relatively difficult concept to grasp and it consumes a lot of memory. Misuse of pointers like wild pointers may cause the system to crash or behave anomalously.
    c. Few blockchains adopt C/C++ as their smart contract language. Rust is often more preferred.
    d. Smart contract code written in C/C++ is not concise compared to Solidity.
  4. References:
    C Wiki, Advantages and Disadvantages of C Programming, my own experiences
    Links: Github (stars: 168), documentation for EOS, documentation for Solana

Go

  1. code example (hyperledger), Token contract on Neo
  2. Supported blockchains: Hyperledger Fabric, Neo
  3. Syntax similar to: (Existing language modified to support smart contracts)
  4. Built with: Go
  5. Turing completeness: True
  6. Support loops: True
  7. Interpreted or compiled language: compiled
  8. Trend ranking based on Github stars: 3
  9. Most loved ranking based on Stack Overflow survey: 5
  10. Description
  1. Facts:
    a. Introduced by Google in 2009, Golang is a statically typed programming language to make efficient server-side software.
  2. Pros:
    a. Go is the go-to language for writing Hyperledger Fabric (a permissioned, enterprise-focused blockchain framework) smart contracts.
    b. Good performance like C/C++. With similar syntax simplicity, Go is typically 40 times faster than highly optimized Python.
    c. Blazing fast compile time (usually finished in seconds).
    d. Has a rich standard library. Developers don’t have to import or learn complicated secondary libraries.
    e. The syntax is relatively simple, easy to learn and read.
    f. Simpler code is generally safer than complicated code. Easier to identify errors.
  3. Cons:
    a. Does not support object-oriented programming.
    b. Lack of a single dominant framework like Rails for Ruby and Django for Python.
  4. References:
    Golang Wiki, Golang vs Rust, Rust Vs Go: Which One To Choose And Why?, Should I Go? The Pros and Cons of Using Go Programming Language, Why we switched from Python to Go
    Links: Github (stars: 87.8K), documentation for Hyperledger Fabric

C#

  1. code example
  2. Supported blockchains: Neo
  3. Syntax similar to: (Existing language modified to support smart contracts)
  4. Built with: C#
  5. Turing completeness: True
  6. Support loops: True
  7. Interpreted or compiled language: compiled
  8. Trend ranking based on Github stars: 9
  9. Most loved ranking based on Stack Overflow survey: 8
  10. Description
  1. Facts
    a. Developed around 2000 by Microsoft as part of its .NET initiative, C# is a general-purpose and object-oriented programming language.
  2. Pros
    The syntax is relatively easy to learn, write, and read.
    C# code can be run on embedded systems.
    Game developers that use Unity for game development are already familiar with this language.
  3. Cons
    Few blockchains adopt it as their smart contract language.
    The performance is not as good as C/C++.
    More memory-consuming compared to C/C++.
    Requires the correct version of the .NET framework to be installed to run the program, which leads to a longer setup time.
  4. References
    C# Wiki, What are the pros and cons of C# vs Java?, my own experiences
    Links: Github (stars: 7.2K), documentation for Neo

Clarity

  1. code example (NFT)
  2. Supported blockchains: Stacks (Blockstack-backed, a layer-1 blockchain that brings smart contracts and decentralized apps to Bitcoin)
  3. Syntax similar to: Lisp
  4. Built with: Rust
  5. Turing completeness: False
  6. Support loops: False
  7. Interpreted or compiled language: interpreted
  8. Trend ranking based on Github stars: 40
  9. Most loved ranking based on Stack Overflow survey: (No relevant data available)
  10. Description
  1. Facts
    a. Created in 2020, Clarity is a new programming language for writing smart contracts on the Stacks 2.0 blockchain. Stacks 2.0 anchors clarity smart contracts to Bitcoin making it possible for smart contracts to operate based on actions seen on the bitcoin blockchain.
  2. Pros
    Developers can use Clarity to write readable code that works with the Bitcoin blockchain.
    Clarity is a decidable language. One can know from the code itself what the program will do.
    Clarity is intentionally Turing incomplete. This allows for a complete static analysis of the entire call graph of a given smart contract.
    As an interpreted language, it has no compiler and thus no compiler bugs.
    Secure by design: reentrancy is not allowed and checks for underflows and overflows.
    The syntax is easy to learn, write, and read once you are comfortable with the parentheses.
  3. Cons
    The language is very young. It takes time for the language to prove itself to be secure and not error-prone.
    The only blockchain it supports is Stacks. The smart contract code cannot be ported to other existing blockchains.
    The intentionally limited design can make it more difficult to create smart contracts.
    Since this language is nothing similar to Solidity, the ecosystem of Stacks needs to be built from scratch.
    The examples and tutorials are relatively few.
  4. References
    Stacks whitepaper, Clarity book, my own experiences
    Links: Github (stars: 103), documentation, Clarity Visual Studio Code plugin

Move

  1. code example
  2. Supported blockchains: Diem (Facebook-backed), Pontem
  3. Syntax similar to: Rust
  4. Built with: Rust
  5. Turing completeness: True
  6. Support loops: True
  7. Interpreted or compiled language: interpreted
  8. Trend ranking based on Github stars: (No relevant data available)
  9. Most loved ranking based on Stack Overflow survey: (No relevant data available)
  10. Description
  1. Facts
    a. Presented in 2019, Move is an executable bytecode language used to implement custom transactions and smart contracts. The key feature of Move is the ability to define custom resource types. A resource can never be copied or implicitly discarded, only moved between program storage locations. The language was created to solve problems of existing smart contract languages, such as eliminating the possibility of reentrancy. It also adds flexibility by adopting concepts similar to object-oriented programming such as modules.
  2. Pros

Flexibility

  • Move introduces the concept of “transaction script”, which allows one-off behaviors and reusable behaviors, while other smart contract languages only allow reusable behaviors.
  • One-off behavior: paying a specific set of recipients
  • Reusable behavior: invoking a single procedure that encapsulates a reusable logic

Safety

  • As an executable bytecode language, Move adopts a bytecode verifier and a bytecode interpreter instead of a compiler like Solidity, which makes it free from possible failures or attacks in compilers, as stated in the Solidity official documentation.
  • Each asset in Move has native scarcity and access control properties.
  • Solidity has no native scarcity check. When new tokens are minted, you have to manually check if scarcity (total supply in this case) has been reached.
  • Solidity has no native access control check, you have to write modifiers like onlyOwner.
  • Move Introduces the concept of “resource”, which can never be duplicated or implicitly discarded, it can only be moved between program storage locations. This is similar to a “token” in other blockchains.
  • For example, Coin is a resource, which can only be moved once from one location to another and cannot be copied or double-spent.
  • In Solidity, there is no such concept. The transfer of assets needs to be manually specified, increasing the chance of writing buggy codes.

Modularity

  • Move modules are related to, but not the same as, the concept of “smart contracts” in Ethereum and other blockchain platforms.
  • An Ethereum smart contract contains both code and data published. In Libra, modules contain code values, and resources contain data values.
  • In object-oriented terms, an Ethereum smart contract is like a singleton object published under a single account address. A module is a recipe for creating resources, but it can create an arbitrary number of resources that can be published under different account addresses. (reference)
  • Data in a smart contract can only be modified within the contract scope but not other contracts from the outside. In Solidity, data is not scoped and thus does not have this type of protection.
  • For example, in the following piece of code, only the procedures of the Currency module can create or destroy values of type Coin.
  1. Cons
  1. Since Move is an interpreted language where each line needs to be evaluated at run time, the performance is not as good as compiled languages. Note that this is a tradeoff for security purposes (free from compiler bugs).
  2. The language is very young. It takes time for the language to prove itself to be secure and not error-prone.
  3. The only blockchains it supports are Diem and Pontem. The smart contract code cannot be ported to other existing blockchains. Nonetheless, it is worth noting that Pontem will provide toolings to port applications in the near future. For example, developers can run most of the apps on EVM and create necessary changes in Move with an automated migration tool that replaces legacy code with the current one.
  4. Since this language is nothing similar to Solidity, the ecosystem of Diem needs to be built from scratch.
  5. The examples and tutorials are relatively few.

References

  1. Move whitepaper deep dive, Move whitepaper overview
  1. Special notes: Linkage Between Rust & Move (reference)
  1. If you are familiar with Rust, you may recall the concepts of “resource”, “ownership”, and “move”. In Rust, resources can only have one owner.
  2. When doing assignments (let x = y) or passing function arguments by value (foo(x)), the ownership of the resources is transferred. In Rust-speak, this is known as a move.
  3. This is how the name of the programming language “Move” comes from. After moving resources, the previous owner can no longer be used. This aligns with the properties of digital currencies that cannot be double-spent.
  4. It is also worth noting that the Move language and the Diem blockchain are written in Rust. The team lead on Diem’s Novi wallet team mentioned on Reddit that “As a project where security is a primary focus, the type-safety and memory-safety of Rust were extremely appealing.”
  5. Links: Github (stars: 15.9K), documentation, getting started in Pontem, Move VS Code Extension

Haskell*

  1. code example (Marlowe embedded in Haskell)
  2. Supported blockchains: Cardano
  3. Syntax similar to: Miranda
  4. Built with: GHC (Glasgow Haskell Compiler)
  5. Turing completeness: True
  6. Support loops: False
  7. Interpreted or compiled language: compiled
  8. Trend ranking based on Github stars: 22
  9. Most loved ranking based on Stack Overflow survey: 15
  10. Description
  1. Facts
    a. Haskell is a statically typed, lazy, purely functional programming language. Functional languages are superb for writing specifications that can actually be executed and also easier to maintain.
    b. Haskell is easy to implement a formal verification process checking whether a design satisfies some requirements.
  2. Pros
    Shorter, clearer, and more maintainable code.
    Even if you are not in a position to use Haskell in your programming projects, learning Haskell can make you a better programmer in any language.
    Enjoys all the advantages of functional programming languages.
  3. Cons
    Few blockchains adopt it as their smart contract language.
    Not a lot of developers are experienced with functional programming.
    Very few applications are being built on Cardano, meaning that there are few references for developing Haskell smart contracts.
  4. References
    Haskell Wiki
    The Plutus Platform
    Links: Github (stars: 3.6K), documentation, realtime IDE


Acknowledgment

This work has been reviewed by Chia-Chi Chang, Alejandro Pinto, Chi-Chen Liang, Marvin Janssen, and Sean Sie:)

Wrap up

Now you have an overview of the top 10 smart contract programming languages in 2021, their pros and cons, and comparisons in terms of seven evaluation metrics. If you follow along with the article, you should be able to answer “Why are there so many smart contract languages? What are their differences? Which language best suits my needs”. Hope that this article is helpful to your journey of choosing and learning smart contracts.

Thank you for your time reading. Suggestions are welcomed and feel free to point me out if anything is unclear. See you next time! :)



Install our wallet and try DEX

Related posts

comparison-of-the-top-10-smart-contract-programming-languages-in-2021
614e302d45ade64974a406c0
amb-comparison-of-the-top-10-smart-contract-programming-languages-in-2021