A simple and elegant choice.
Why did you decide to use Rust for Nervos CKB, not C++, Go or Haskell? The answer from CKB developers is as simple as their code — because it’s elegant.
I have always been curious about Nervos CKB development team’s choice for adopting Rust as the language with which our base layer blockchain would be built, because the language itself was still so young one year ago. I asked many of them the question: why Rust, not C++ or Haskell? Their answers are as simple as their code — because Rust is elegant.
Excellent features of Rust
If you are a developer, you might have already found out that the Rust community is very welcoming and active, which gives you much confidence. As developers are also pretty new to this young language, there comes lots of articles and questions on comparing Rust with other programming languages, such as C++, Go, Haskell, etc. But well, newcomers would be trained by the Rust compiler for a while. You are going to love it once you are getting well with it. Someone said it’s Rust let him fall in love with programming again, that you do not worry about your program once the compilation is complete.
Parity and its Substrate, Grin and ChainX are written in Rust, Zcash is considering switching to Rust, there are more than you can see. Check Cryptocurrencies written in Rust.
People love Rust because:
Performance: There is no GC (garbage collector), no runtime, which made memory safety, and integrates with other languages easily.
Reliability: The ownership model guarantee is the unique feature, which Aaron Turon called it as Rust’ secret weapon.
Productivity: The good compiler will turn you into an excellent developer in many ways, such as editor support, type inspections, better formatter, friendly error warning, and a lot more.
Why Rust is perfect for blockchain development
Why Rust is a good fit for blockchain projects?
Building a crypto project usually involve cryptography, mathematics, game theory, economics, etc. There are already many cutting-edge in cryptography such as zero-knowledge proof, ring signature is made in Rust, and there will be more because of the great prospects in Cryptoeconomics. P2P Network and 24/7 network services demand critical highly reliable and performance requirement. The technology is speedily progressed in the Cryptoeconomics world, and a great programming language can speed up blockchain technical iteration in rapid prototyping.
There are C++ implementations for Bitcoin, Zcash, Ethereum, and some cryptography libraries; Fabric, Ethereum Geth and IPFS are written in Go, which was designed as replacements for the C++ implementation; Cardano and Dfinity both use Haskell, because of the language’s powerful type system. Python, Kotlin, Java present some other options for different specific objects.
You may find that programming languages are chasing the same goals, while C can implement extraordinary performance but with lower abstraction and results in human mistakes easily. Functional programming languages, such as Haskell, Idris, are reliable at an excellent level but has a problem with low performance, which is almost no way to raise. Moreover, we see a clear trend towards either projects or developers switching to Rust from C++.
Rust optimizes the system as a whole. It has a competent performance with C++ and outstanding compiler that allows you to program as easy as in Go. With the primary goal of resource management (which including memory, files, network, and thread, etc), it controls resource directly without any abstraction; For reliability, it manages resource and avoids problems such as resource leaks, releases repeated and data race, etc. In terms of productivity, well, just try the excellent compiler.
In conclusion, Rust is a language designed for control , which allows developers to fully manage system resources on their own for more sophisticated primitives, in an elegant way. Not to mention the welcoming and helpful Rust community.
How Nervos bet on Rust
Nervos is a layered Cryptoeconomics network, CKB is its base layer with the full name Common Knowledge Base. CKB team members have been working in the technical area for decades, keep paying attention and never stop trying new technologies as well as contributions to the community.
The conversation of programming language selection started in the fall of 2016. We were eager to find a favorite language that our team would enjoy everyday programming as well as long term blockchain development.
There were Haskell, Erlang, Java, C++, Go and Rust on the table, the first two are too niche that may difficult for recruitment, even though we like Haskell a lot because of its pure functional programming goal. We know Java, C++ and Go very well that we prefer C++’s performance and Go’s efficiency.
Rust is a modern programming language that has absorbed decades of excellence in language design as well as compiler design. We like it very much. Our philosophy is the pursuit of perfection. It’s represented by not only architecture but also the implementation details, whereas there are conflicts between GC and high performance, that we tend to choose Rust without GC.
At that time, we also did a test to compare Go and Rust, a program was written in Rust and Go versions. The Rust version program was still running after 24 hours. All is said and done that security and better performance are the most important points for our product, so that Rust’s standing out addressed the adoption. And, Rust is cool! Especially Rust has shown great strength in engineering which proved the right choice we made.
By the way, there was a story in the earlier time came under the great influence. Ethereum got a DDoS attack (Distributed Denial-of-Service), which affected all clients written in Go and Rust before. Since clients in Rust kept working after that, all miners switched to Rust clients. And most miners and mining pools are using Rust clients nowadays.
Beyond Rust language itself, the Rust community is growing openly with a tolerant magnanimous mind and breadth that we most admire. You would know that every step of Rust improvement is negotiated, consensus achieved and then implemented through the RFC (Request for Comments). The RFC based mechanism has given the Rust language itself great vitality and openness.
We believe that an open culture will bring luck to our team and a better approach to CKB’ success. What’s more, for every Rust programmer, reading the vast amount of high-quality discussion on RFC is in itself a great pleasure and rewarding experience, so we borrowed the RFC mechanism to our Nervos CKB, see Nervos RFC.
A little more about Nervos
We started organizing monthly Rust meetup in Hangzhou since November last year, and we have met some great rust developers in the community.
Nervos CKB team will have a workshop on the topic of “Go Gentle into CKB”, and more frequent Rust meetups in 2019, Nervos dedicates to involve heavily in Rust shortly.