NOTES ON "GO" PROGRAMMING, LEARNED FROM DIVING-IN TO A BLOCKCHAIN PROJECT
I decided to start using the “go” programming language a while ago, but I never had a project that could introduce me to it until recently. There were a few things about Go that I knew already, and they seemed appealing...
It was created by a legit, old-school computing power-trio (Thompson, Pike, Griesemer)
Compiled, but the compiler is extremely fast
Supports user-defined data structures
Not really object-oriented
Has a lot of built-in features to support multithreading
Basically, it’s what Ada should have been but never was. There are also a bunch of things I learned about Go while I worked on my first project:
Go has built-in dependency support
Go has built-in unit test support
There are no makefiles, but you do need to adhere to a particular directory structuring model
It is probably easier to come downstream to Go from Python than upstream from C.
Go tries to protect the coder from pointers, without eliminating pointers — this makes me crazy.
There’s an Old—World attitude about the syntax formatting: technically you have a lot of freedom with the syntax, but in terms of practical culture, you do not. Go will sneakily adapt your syntax to its own ideal.
Go’s write-test-deploy model is faster than pretty much anything else’s is — including any LISP.
The whole reason I embarked on learning some Go is because there was a minimum viable blockchain project I found, implemented in Go. I wanted to play around with it, and test it. I’m not even going to bother showing code snips, because they are freely available. Here’s what an observer should know about getting started with Go.
1. Install Go. You probably need Mac or Linux. If you’re reading this, you probably already have Mac or Linux.
2. Edit your .profile file to include:
Go has a strict directory structure model. This took me a while to figure out. Go doesn’t appreciate creativity, here. You need to put all of your source in another directory called $GOPATH/src. By “all source” I mean every Go source code project you ever create or download. Yes, you can set up nested directories. In fact, Go sort-of fits right in to Git. If you’re downloading Git repos into $GOPATH/src, everything just works.
3. Download github.com/izqui/blockchain into $GOPATH/src
4. Run a Go command to download dependencies
$ cd $GOPATH/src/github.com/izqui/blockchain
$ go get
5. izqui/blockchain had some bugs. Once you fix them you can run the following command, and expect the following output (or similar). Go supports inline testing, which is really handy. You just name test codefiles with “_test.go” at the end. Yeah, pretty easy.
$ cd core
$ go test -v
=== RUN TestMerkellHash
--- PASS: TestMerkellHash (0.14s)
=== RUN TestBlockDiff
--- PASS: TestBlockDiff (0.07s)
=== RUN TestKeyGeneration
--- PASS: TestKeyGeneration (0.00s)
=== RUN TestKeySigning
--- PASS: TestKeySigning (0.03s)
=== RUN TestMessageMarshalling
--- PASS: TestMessageMarshalling (0.00s)
=== RUN TestPow
--- PASS: TestPow (0.00s)
=== RUN TestTransactionMarshalling
--- PASS: TestTransactionMarshalling (0.13s)
=== RUN TestTransactionVerification
--- PASS: TestTransactionVerification (0.01s)
=== RUN TestIncorrectTransactionPOWVerification
--- PASS: TestIncorrectTransactionPOWVerification (0.00s)
=== RUN TestIncorrectTransactionSignatureVerification
--- PASS: TestIncorrectTransactionSignatureVerification (0.01s)
ok github.com/izqui/blockchain/core 0.413s
6. You can deploy the command line client to this program equally as easily.
$ cd ../cli
$ go install
$ cd $GOPATH/bin
So, that’s my first experience with Go. I expect I’ll use it as a replacement for anything between C and Python (but not replacing C or Python for me). It is really quite streamlined.
XLP Capital is a family office and as such is not required to be registered as an investment adviser with the U.S. Securities and Exchange Commission. Investments are made available only to accredited, qualified, or institutional investors that are eligible as family office clients, pursuant to the rules of the U.S. Investment Advisors Act of 1940. XLP does not seek or solicit investment for these funds or any other funds, and nothing on this page should constitute a solicitation for investment. The descriptions on this page is provided for information value only, as examples of prior investment related work XLP has conducted. XLP Capital assumes no liability for investment losses direct and indirectly resulting from recommendations made, implied, or inferred by its research. Likewise, XLP Capital assumes no claim to investment gains direct or indirectly resulting from trading profits, investment management or advisory fees obtained by following investment recommendations made, implied, or inferred by its research. Investment involves risk, and all investments should be made with the supervision of a professional investment manager or advisor. The materials on the Website are not an offer to sell or a solicitation of an offer to buy any investment, security or commodity, nor shall any security be offered or sold to any person, in any jurisdiction in which such offer would be unlawful under the securities laws of such jurisdiction.