The Go Story

Saurabh Nayar
Higher-Order Functions
10 min readMar 12, 2020

Go is a general-purpose, statically typed, compiled language designed at Google. Go has been growing in popularity and is quickly establishing itself as a popular enterprise application development language. As per Stackoverflow Developer Survey 2019, Go programmers, on average, earn way more than Java programmers. And the number of Go developers has been increasing for several years — Stackoverflow Developer Survey 2019 vs Stackoverflow Developer Survey 2018.

The World before GO

Programming languages have bigger moats than most of us realize. For an enterprise, it is not easy to switch to another programming language — COBOL gained its popularity in the 1970s and is still around. Java has been the most popular enterprise application development language since the early 2000s and will continue to be around for a long time to come.

In this world of enterprise application development, the choice of a programming language is mostly a top-down decision. Lots of factors come into play — learning curve, availability of skilled programmers, resistance from the existing programmers, language product support, community support, maturity of the language, the maturity of the libraries & frameworks, availability of database drivers, no established design & coding styles and practices. There is also the cost of legacy — enterprises still have to maintain their existing applications written in COBOL and Java.

So, why do enterprises switch to a new programming language? There has to be a key defining factor that so endearing that the enterprises take the plunge. For Java, the key feature was interoperability. Of course, Java is Object-Oriented, and safe (as compared to C, C++) — and these features help too — but the reason why enterprises switch is that they were not tied to proprietary hardware (as compared to COBOL). Write the code once and run it on Windows, Mac, Linux and even on Mainframes.

Case for Disruption

Many believe that Moore’s law is dead. Single-core processor speed has not increased in years — Multi-core processors are the new norm. Intel Core i7 1st generation had 4 cores. Intel Core i9 supports up to 16 cores. Existing languages (including Java) are not equipped to take advantage of the changing landscape.

Java uses Native OS threads for concurrency. Native OS threads are acquired from the operating system and have higher memory requirements as compared to Green Threads. Green Threads are threads maintained by a run-time library or virtual machine.

Go multiplexes multiple threads on Native-OS threads. And Go threads (Not threads but Go routines) are very memory efficient. You can spawn thousands of go routines with the given memory footprint as compared to Java wherein you run out of memory very quickly as the number of threads increases. Additionally, Go provides inbuilt support for Communicating Sequential Processes (CSP) concurrency patterns. And there are lots of other good features — Easy to learn, community support and backing from Google. We will discuss those in the next sections.

Who does GO?

Many companies have adapted GO — Paypal, American Express, Mercado Libre, Salesforce, Capital One, Target, Twitch, Netflix, Twitter, Uber, and DropBox. [Source: https://go.dev]. Needless to say, Google is using GO for many of its own projects — that is why they created it.

And there are many Open Source tools/frameworks/Databases written in Go. Here are few — Kubernetes and Docker [Enabling container ecosystem], Go-Ethereum [Blockchain], Influx and Prometheus [Time series databases], Cockroach DB, TiDB [Distributed SQL Databases], Grafana [Metrics Analysis & Dashboarding]

Where does GO stand? The standard features

Go is compiled

Programming Languages are generally categorized as compiled or Interpreted. A compiled language converts the source code directly into object code. Object code is native to OS and can be executed directly or with the language run-time library. Interpreted languages execute the code directly without the whole file into object code — they convert the source into object code line-by-line. It is not too tough to see that Compiled languages have a better opportunity to optimize object code — generally, speaking compiled languages run faster. And GO is compiled.

Python is interpreted, C/C++ are compiled, Java is somewhere in between — it compiles source code to “byte-code” and then interprets the byte-code.

Go is statically typed

A language is statically typed if the data type of the variable is known at compile time. Dynamically typed languages don’t have this requirement — the data type of the variable is rather interpreted at the run-time. In my opinion (and of many others), statically typed are safer — you know what you are getting at compile time — this should be a key requirement for enterprise application software where surprises at run-time can be very costly.

C, C++, Java, Go are statically typed. Javascript (Nodejs), and Python are dynamically typed.

Why should you GO?

Below is a list of key reasons you should try GO — some of them may be more relevant to you than others.

Need For Speed

I have already discussed this above. In my opinion, GO Routines are faster, simpler, better than the threading model in any other programming language. Spawning a new GO Routine is super easy. And GO also provides language constructs that enable communication between two routines using channels — it is a lot safer than just using shared memory.

Middling Learning Curve

“Less is More” — An old proverb

For many, this can easily be most endearing of the reasons to learn GO. As a language, there not much “new” introduced in GO — which, my opinion again, is a good thing. GO has limited “features” as compared to other languages — but it has the best features. Minimalism is not easy.

If you are new to programming, GO is probably a better language to start. There is a lot less clutter — and a lot more is explicit. Explicit is better than magic.

If you have already spent a few years programming, GO is easy to grasp. You have used most of the features already. Your new learning goals should be to UNLEARN. Trust me, in the long run, you will be happier will lesser features.

Rock Star Creators

Ken Thompson is known for his contributions to Unix Operating System. He also created programming language B — the predecessor to C.

Rob Pike is best known for his work in Bell Labs where he was involved in the creation of the Plan 9 from Bell Labs and Inferno operating systems

Robert Griesemer is known for his work on code generation for Google’s V8 JavaScript engine, the design and implementation of the domain-specific language Sawzall, the Java HotSpot virtual machine, and the Strongtalk system.

Ken, Rob, and Robert had years of programming experience and their insights help shape the language. Rob Pike shared his story about creating GO in an interview [GoTimeFM]. Here is what he said:

I’m not sure exactly how it started, but the story we like to tell is we’d just seen a talk about a new release, a new version of C++, which was the language that most of the server software was written in at Google… And I had been thinking for a while about how inappropriate C++ was, because it lacked support for the new multi-core machines we were getting, and how I wanted to go back to some of the ideas I had explored many years earlier with concurrent programming… And then we were sitting — Robert and I shared an office, and sometime in September 2007 I think I literally turned my chair around to Robert and I said “Hey, Robert, we should do something about this.”

We talked for a few minutes, and then Ken was in the next office, so I ran and got Ken and said: “Do you wanna help?” He said yes, and that was it.

Backed by Google

Google has been a very successful software company. And they do some freaking complicated stuff. It is in Google’s best interest to make GO successful. Google made GO open source — and started involving the larger community — this has not helped other enterprises adopt GO, but also created a way the bigger pool of GO programmers.

Google has invested substantially in this new language — and they are reaping benefits now. Google and other open-source contributors will continue to strengthen this language as there is a clear return on their investments. If it is good enough for Google, it is good enough for many other enterprises.

The good OO

My biggest problem with Java has been the complicated Object Oriented constructs. More often then not, we ended up creating a mesh of objects and interfaces — with a focus on Extensibility and DRY principles.

Extensibility — in this context — meant the ability to enhance existing behavior by adding new code with minimal changes to existing classes. And this is good OO. DRY or “Don’t Repeat Yourself” — means that you don’t rewrite the same code again and again — and that is good too — for the most part.

But then there are constructs in Java that are supposed to make the key ideas of encapsulation and polymorphism more useful — Overriding methods, different access modifiers, inheritance, abstract classes, interfaces with default methods, friendly methods, static methods in interfaces, multiple inheritances and Diamond problem — and you are thinking about how programming language is going to behave rather than the business problem, business entities, and encapsulation.

It is not that Java’s OO stuff is totally useless. It is not as useful as the core encapsulation ideas. It is just that the additional OO constructs take away substantial cognitive ability — that it might be more useful to not to use the additional features and stick the core OO philosophy. That is precisely what GO did. And trust me — it is a lot less strain on your brain and lot more productivity.

Standard Formatting Rules / Tools

If you are a programmer and love sitcoms — I will recommend you to binge-watch HBO Go’s “Silicon Valley”. There is an incident in one of the episodes wherein the protagonist, a programmer of course, gets into a fight with his girlfriend, another programmer, over the use of tabs vs spaces in code. And they break up over formatting rules.

Formatting code doesn’t mean much to me — or to most programmers — but it matters to the team as a whole. Different formatting in the same code base — is irritating, at the least. GO solves this problem for good:

  • There are standard formatting rules. Every developer has to adhere to it. And since there is no choice — it leaves less scope for disagreement. Teams can focus on business problems and not something as trivial as code formats.
  • All GO code follows the same formatting standard — it makes it a little bit easier for a new programmer joining your team
  • The tools to format your code come packaged with the SDK — the cost of keeping your code formatted is really low — and thereby tech leads and code maintainers don’t have a tough time enforcing the standard formatting rules.

Awesome Standard Library / Backward Compatibility Guarantee

GO comes with a standard library that is written by creators of the programming language. Since GO 1 has a promise to be backward compatible, the standard library will also remain backward compatibility. This is a big deal — you can write code and be confident that it will continue to work for the next 5–10 years. Change in open source libraries or new enhancements in the language will not break you.

This is why the standard library is special:

  • It offers a lot more than the standard libraries from other languages. GO has complete HTTP server as part of the standard offering
  • It gives the programmer confidence that new releases will always remain backward compatible.
  • It acts as a reference code. Since it is created by creators of GO itself, it provides insights into how the code is supposed to be written, what creators had in mind when they were designing the language.

Super Cool Tooling

GO provides lots of very useful tools. We have already discussed one — formatting code — go fmt. This tooling support from GO makes the language even more endearing for code maintainers — it reduces the overall cost for quality. Here are some of the super cool tools:

  • Identifying race conditions — Asynchronous code is always tough. GO routines and channels make it easy to write — but what about the race conditions that don’t generally happen when you are testing — but create havoc in the production environment. go test -race let you run test cases that also evaluate code for race conditions
  • Static code analysis using go vet. GO Vet checks for lots of things — common mistakes on sync, atomic packages, using unsafe pointers, using nil values etc.
  • golint provides further insights into code styles, naming conventions and more.
  • Bench-marking — Golang provides the ability to benchmark functions — just as it provides the ability to write test cases. I haven’t seen this in any other language
  • godocs and examples — It provides the capability to generate documentation of your code. You can also refer to documentation /examples of any library function you may be using.

Conclusive Remarks

After we have adopted GO, programming has become more of a commodity — things are standardized and the learning curve is not so steep — it is easier for programmers to switch from one project to another — and it is a good thing. As a programmer, you get a lot more exposure and it is only good that you can be replaced by another programmer — you can switch teams, get promoted and are not bound to your existing project.

While other languages boast of features, GO boasts of simplicity and lack of features. There is a certain philosophy that is unique — and, in my opinion, fruitful. GO is fast establishing itself as a language for enterprise application development. It is so good that it cannot be ignored completely — whether you like it or not — it is definitely worth trying.

--

--