Ultimate Cheat Sheet To Start Coding In Blockchain: How Can We C?

Kushagra Singh
Neptune Blockchain
Published in
4 min readJul 12, 2018

--

In the previous blog, we have covered fundamentals of blockchain, basic terminologies and brief about popular coding languages in Blockchain technology.

If you have not read my previous article, follow the link: Ultimate Cheat Sheet To Start Coding In Blockchain: The Fundamental

This article will focus on Blockchain coding resources for C/C++.

Why are we using C++ for coding in Blockchain?

There are a variety of reasons why C++ is an excellent language choice for blockchain applications like Bitcoin.

Blockchain applications have a large attack surface. They’re meant to interoperate with a large number of untrusted endpoints while still providing reliable service to local clients. This requires keeping tight control over resources like memory and CPU usage.

Modern CPUs have lots of cores. Some parts of blockchain applications parallelize perfectly (like checking digital signatures) while some parts don’t parallelize at all (like executing transactions in order). Modern C++ has a very good mix of effective inter-thread communication and optimization of single-thread performance.

C++ doesn’t have a run time that stops the world or manages memory, giving your application consistent control over this behavior. Move semantics allow you to get objects that behave like values (a=b; a+=1; does not change b) but perform like references (deep copies are avoided except where needed).

Smart pointers allow you to avoid the costs of GC without the tedium of manual memory management. Design patterns like RAII makes code easier to maintain. Template metaprogramming facilitates independence between APIs and implementations.

C++’s inheritance scheme makes the design of complex type hierarchies easier.

The language is both mature and maintained. The compiler technology is extremely solid, yet new features are still being added. And the new features are aimed at solving real issues. Debuggers and analytical tools of all kinds are available for everything from performance profiling to automatic detection of issues of all kinds.

To summarize the features of C++

  • Memory control: A blockchain is supposed to interact with a lot of untrusted endpoints while still giving quick service to any and all nodes.In order to satisfy all these demands and perform at the highest level, you need tight and complete control over CPU and memory usage. C++ gives that to its users.
  • Threading: one of the main challenges of the blockchain programming is the integration of tasks that parallelize well and the tasks that don’t parallelize. Most languages specialize in one, however C++’s threading ability is good enough to handle both parallel and non-parallel tasks.
  • Move semantics: Move semantics provides a way for the contents to be moved between objects rather than be copied outright.
  • Compile time polymorphism: Using polymorphism, you use a particular feature in more than one ways. Details here
  • Code isolation: C++ has namespace features which can be imported from one program to another. Namespace helps in avoiding name collisions. Also, since C++ has classes, it can act as boundaries between various APIs and help in making clear separation.
  • Maturity: The language is both mature and regularly updated.

Learning resources for starting in C++

I have curated some resources which can help you in starting/ brushing up your C++ skills.

  • Learn C++ — Covers a large number of topics and a good website for someone who previously knows some programming language.
  • Codesdope — A very good website for those who wish to learn a language completely from complete beginning. Its tutorials are also easier to understand.
  • Cplusplus — Another good website for learning C++.

How to Blockchain with C++

There are various examples across the web, which provides handson tutorials, I have curated the best ones here.

Simple implementation of blockchain in C++.

https://github.com/tko22/simple-blockchain

What’s next?

If you like this blog, give me few claps and give us a shout out in your community. Share this blog with your developer friends. Join our developer channel on telegram for the best curated jobs, news, Bug bounties, resources and more. We would love to hear your valuable feedback on our work.

References:

--

--