Many different computer programming languages are employed in cryptocurrency programming.
In this article, we take a look at cryptocurrency projects and the languages they employ.
We briefly discuss each language while highlighting their main characteristics, learning difficulty and how they are deployed in different crypto software projects.
Haskell is the world's only widely adopted general purpose purely functional programming (FP) language. There are other purely functional dialects, but they're usually limited to domain-specific applications.
It is unique in the fact that it does not allow any exceptions to the functional programming paradigm, unlike mixed functional/object-oriented languages like Scala and OCaml. This functional purity makes Haskell a favorite language of mathematicians, logicians and FP enthusiasts. Cryptographers usually come from these fields of study, so Haskell is slowly growing within the cryptocurrency development field.
Why is the purely functional paradigm desirable in cryptocurrency and blockchain software development? There are many reasons for this, but we'll approach some of the most important ones.
Firstly, purely functional programming means that data is immutable and only functions can manipulate input and produce a different output. In Haskell you cannot say that a variable is equal to the number 3 and then say it is equal to the number 10. Once a "variable" (a constant, to be precise) is named in Haskell, it will always mean the same thing. This is a very special trait in decentralized systems. The blockchain itself is immutable and when you have millions of users processing data simultaneously it is important to guarantee immutability so that the parallel processing of this data will produce the same result no matter where it happens. Millions of nodes process blockchain transactions at the same time and they all must reach the same consensus. Therefore functional programming's data immutability is a very desirable trait in parallel decentralized applications.
Secondly, most formally verified software systems, like the Coq proof assistant, are written in functional programming languages. This is due to the fact that formal verification uses mathematical concepts and functional languages are very close to mathematical principles. In fact mathematicians usually feel at home working with FP, especially when they apply programming concepts that are directly derived from algebraic structures like monads, partial functions, set theoretical concepts and so on.
The Haskell learning curve is steep, especially for non-math oriented folks. Experienced object oriented or structured programmers with long time experience in these paradigms usually face difficulties learning Haskell. Some Haskell tutorials begin by saying "forget all that you had learned about programming before" and this is no understatement. Haskell requires a completely different view of software development than that used on most other popular programming languages.
Cardano ADA uses the Haskell programming language for its core technology.
OCaml is a functional programming language derived from ML.
As we mentioned in the section about Haskell, functional programming languages usually can be formally verified. In fact, the Coq proof assistant, used for formal software verification, can produce 100% guaranteed correct OCaml code.
OCAml is Turing-complete and can be used for any kind of programming, from system-level development to data-driven business system backends.
The Tezos cryptocurrency is written in OCaml and has some formally verified components.
If you wish to extend or modify Tezos, you may want to learn OCaml.
OCaml can be difficult to learn, especially if you've never programmed in a functional language before.
The same observations we made about Haskell are valid here. In fact most functional programming languages are similar in concept. To program in a functional paradigm, you must "unlearn" a lot of what is taught in imperative language theory.
Other than that, OCaml is a clean and elegant language that is definitely worth including in your arsenal.
Rust is a relatively new systems-level programming language that is beginning to gain ground in cryptocurrency development.
Some of the new Cardano components, such as the jormungandr full node implementation, are written in Rust.
Rust is meant to be low level while incorporating modern language features. Its main application are is to substitute C++ as the de-facto low level systems development language.
Systems written in Rust do not have to manually manage memory and pointers. But, unlike Java, Rust does not require a runtime virtual machine. The memory management strategy is compiled along with Rust programs, such that there's very little runtime overhead. For this reason, Rust is ideal for cryptocurrency development, as cryptographic routines can be implemented in a fast and secure language.
Rust is relatively hard to learn.
Like C++, it is meant for systems development. It therefore includes many levers and switches that you must learn to work with in order to write efficient programs.
At a basic level its syntax looks a lot like a mix between C and Scala. You can program basic Rust solutions without knowing the entire language.
As you delve deeper into the language features, Rust begins to show its true power and versatility. That's when it begins to differentiate itself from other languages.
Go is a systems programming language developed by Rob Pike at Google.
In fact Go is named that way because it's a prefix for Google. It is a low level programming language that aims to be very fast, to offer modern concepts but to remain close to the machine.
The Go language is well suited for cryptographic programming, which usually requires proximity with the computer hardware in order to exploit its optimizations.
The Go learning curve can be steep. It looks fairly familiar to C-style language programmers but that's only superficially. Developers aiming to enter the Go field should prepare to learn a lot of new basic concepts before becoming well versed in the language.
Go is the language used in the ubiquitous geth Ethereum client.
Solidity is a Turing-complete language designed specifically for smart contract development.
Ethereum was the first system to deploy Solidity through its EVM technology (Ethereum Virtual Machine).
Solidity is relatively easy to learn.
The biggest challenge in developing smart contracts is not the language itself, but the smart contract logic. Very subtle details in smart contract design can allow attackers to steal funds (see The DAO hack).
Solidity is used in Ethereum, Ethereum Classic and most cryptocurrencies forked from these.
freeCodeCamp offers a crash course to get you started programming Solidity:
Although not very big in the cryptocurrency universe, Java is the world's most popular programming language according to the TIOBE index.
Java was created by James Gosling, a famed engineer who worked at Sun Microsystems, as a replacement for C++. Initially (internally at Sun) it was called Project Oak, but was later renamed to Java for the public release.
The first publicly available version of the language launched in 1995 and caused an earthquake in the world of software engineering. Java adopted the C++ syntax with modifications, allowing C++ programmers to migrate more easily.
Its initial motto was "Write once, run anywhere" which, for many years, was true only in part since Java wasn't very stable on several platforms. To allow Java programs to run anywhere, Sun introduced the Java Virtual Machine. This virtual computer was a layer of compatibility between the machine and Java programs.
A Java program was not compiled to the physical computer's language, but to an intermediary language called bytecode.
Bytecode generated once could be interpreted by any Java Virtual Machine, anywhere. But this interpretation step was very slow and made Java gain an early fame for sluggishness and software bloat. Java based editors like Eclipse were slower than Emacs and other native editors, early Java based programs like JBuilder were also very slow.
Later this was optimized by using JIT (Just in Time Compilation) and other tricks to make Java programs almost as fast as native software. Today, with the parallelization and other optimizations available in most modern CPUs, Java performance is almost on par with native code.
Java has a gigantic community behind it, the Apache Foundation produces tens of amazing projects based on Java and all these libraries can be used freely in your projects. It is indeed an amazing language with a brilliant community behind it.
We left this biggie for last. C++ may as well be the mother of all cryptographic projects. It is, of course, the language used by Bitcoin Core and every first generation crypto either adapted C++ code itself or translated the Bitcoin C++ ideas to other languages (which is how the GPU code that killed CPU Bitcoin mining came to be).
Early in the history of cryptocurrencies, sparked by Bitcoin of course, most projects were implemented in C++ with front-ends written using the ubiquitous Qt framework. The best mining software and most native wallets were all written in C++ in the early days of crypto.
C++ is a very complex language.
Some folks approach it as a "sophisticated C", in which case it's perfectly fine to write C programs in C++ since the former is a subset of the latter.
Any C program will compile just fine under a C++ compiler, which leads a lot of developers to mix these two languages. But do not fool yourself. The C++ semantics are a lot more complex than C.
C++ allows for multiple inheritance, which itself can be a trap for new developers and should be used very carefully when designing class hierarchies.
Having said that, the C++ learning curve can be very steep.
If you use it like C then starting to produce working programs can be quick. But once you dive into the intricacies of C++, especially modern C++, prepare to devour quite a few books before you fully grasp the intricacies of this language.
Cryptocurrency projects which use C++ include Bitcoin and, as mentioned before, most first generation coins forked off of, or which were based on concepts from, Bitcoin.
Stellar uses the C language, which we will include under the C++ umbrella for the purpose of this article.
Several other programming languages are used in cryptocurrency development but here we've covered the main ones.
We hope this brief tour through the main programming languages used in cryptocurrency programming will help guide you to learn more about software development in this exciting new field!