Community Perspective: How I Transitioned from Java to Go Blockchain Engineer
foreword
secondary title
I have been doing Java development before I joined Bytom Chain. I was a little hesitant when I first saw Go, and I was afraid that I would not be able to pass the interview. As a result, the consideration of mastering a language was really not that high. I successfully joined Bytom Chain, and in Within half a month, I quickly mastered Go and was able to develop core projects.
The Java language has advantages in larger mature projects, but it does have many shortcomings in blockchain development, such as in coroutine processing, and the Java language itself is not flexible enough, etc. Of course, the main reason for choosing Go is its The popularity of the blockchain.
secondary title
The Popular Language of Blockchain
Make a little statistics on the programming languages used by more famous projects, as shown in the figure below:
The old generation of public chains, such as Bitcoin and Litecoin, generally use more C/C++ (let’s look at that time, when Go hadn’t started yet), and the new generation of public chains such as Ethereum, the leader of the alliance chain, Hyperledger, started to use more Using the Go language, of course we have seen that the development momentum of Rust is also very strong. In the past two years, many public chains such as Polkadot and Grin have begun to use the Rust language for development.
secondary title
Advantages of the Go language
easy to deploy
Go compilation produces a static executable with no external dependencies other than glibc. This makes deployment extremely convenient: only a basic system and necessary management and monitoring tools are needed on the target machine, and there is no need to worry about the dependencies of various packages and libraries required by the application, which greatly reduces the burden of maintenance. It can be directly compiled into machine code without relying on other libraries. The version of glibc has certain requirements, and the deployment is completed by throwing a file up.
excellent performance
Although not as good as C and Java, it is usually an order of magnitude higher than native Python applications, and is suitable for writing some bottleneck businesses. Memory usage is also very low.
Concurrency & Channels
Goroutine and channel make it easy to write highly concurrent server software. In many cases, there is no need to consider the locking mechanism and the various problems caused by it. A single Go application can also effectively utilize multiple CPU cores, and the performance of parallel execution is good.
good language design
Go is very simple and easy to learn. From an academic point of view, the Go language is actually very mediocre and does not support many advanced language features; but from an engineering point of view, Go's design is very good: the specification is simple and flexible enough. Thanks to Go's simplicity, any Python, Elixir, C++, Scala, or Java developer can form an efficient Go team within a month.
Standard Libraries & Tools
Go currently has a large number of built-in libraries, especially the network library is very powerful. More importantly, Go comes with a complete tool chain, which greatly improves the consistency of team collaboration. For example, gofmt automatically typesets Go code, which largely eliminates the problem of inconsistent typesetting styles of code written by different people. Configure the editor to automatically run gofmt when editing the archive, so that you can place the code at will when writing the code, and it will automatically become the correct typesetting code when archiving. In addition, there are very useful tools such as gofix and govet.
Great team
The supporter behind the Go language is Google. The language is enough to be tested in various scenarios. At the same time, the founder is also the father of the C language, and the follow-up development and innovation can be expected.
Go successful projects
The Go language has been widely used in the cloud era, especially the emergence of killer products such as Docker and K8s has given the Go language a place in the engineering world.
In addition, the Go language has a lot of successfully running software:
nsq: Bitly's open-source message queue system has very high performance. Currently, they process billions of messages every day;
packer: used to generate image files for different platforms, such as VM, vbox, AWS, etc., the author is the author of vagrant;
skynet: distributed scheduling framework;
Doozer: a distributed synchronization tool, similar to ZooKeeper;
Heka: mazila open source log processing system;
cbfs: Couchbase open source distributed file system;
tsuru: an open source PAAS platform, which has exactly the same functions as SAE;
god: a cache system similar to redis, but supports distribution and scalability;
gor: Network traffic capture and replay tool;
secondary title
Ecological slots and implicit standards
In addition to the hard work required to strike iron, there are also some opportunities and fortunes that make the blockchain choose the Go language. Let’s look at the most successful representatives of public chains and consortium chains since Blockchain 2.0, Ethereum and Hyperledger Fabric, all of which have chosen to use Go as the leading development language without exception.
The influence of these two super blockchains is not comparable to that of ordinary projects. They not only occupy a large niche in the ecology, but also implicitly formulate the standards of the blockchain, whether it is the intelligence in the public chain Neither the contract nor the technology of the alliance chain can bypass Ethereum and Fabric. So for a company that wants to choose a blockchain technology, what is the fastest way to achieve it? Naturally, it is to directly copy the innovations of these two projects, and a shortcut is to directly use the open source code to modify, then naturally the Go language becomes the first choice for latecomers. It is not easy to re-implement it in another language, and if you choose some innovations but not A very mature language will also lack support for some specific libraries, making the project impossible to carry out.
Many people have no doubt about the influence of Ethereum, but in fact, the influence of Fabric on enterprise blockchain deployment should not be underestimated:
Hyperledger Fabric is the most used protocol framework among deployed enterprise blockchain networks, and Hyperledger (of which Fabric is the flagship protocol) is the protocol framework most commonly supported by integrators and software development platforms, accounting for 53%.
Among all the blockchain technology books, the fact that books about hyperledgers are the most popular is also a side confirmation of the influence of Hyperledger.
secondary title
The practice of Bytom in Go language
In the process of selecting a programming language, C, C++, and Java were considered, but C/C++ is difficult to maintain for large projects, and Java is a bit cumbersome. At this time, the Go language has already shined in the blockchain project. Gradually forming a head effect of technology and talents, then following the trend of technology selection will naturally reduce the resistance encountered by the initial Bytom project. Of course, in the gradual development process, we also feel the convenience brought by the choice of Go language and advantages.
A Case of Go on Blockchain
Technically speaking, blockchain nodes require multiple modules to work together asynchronously, so Go language concurrency and channels are very advantageous. Let's look at the following example of transaction verification:
We can use Routine+Ch+WaitGroup to build a concurrent verification transaction function within 30 lines of code. In the case of a high-configuration server, it can run more than 100,000 TPS.
Easily become a Go language master
In terms of collaboration, automatic typesetting of Go code through gofmt can minimize the differences in code styles submitted by core team members and even community developers, and improve the overall quality and maintainability of the project.
Summarize
secondary title
Summarize


