Golang and why it matters

What Golang is all about:

  • It is a statically typed, fast compiled language designed for modern development.
  • Produces binary executables, like c++
  • Powerful at Concurrency with inbuilt primitives and features to allow systems to be built to scale and effectively use the computing power available.
  • Simple but Opinionated
  • Empowered by the open source community; all users are encouraged to put their go projects on github.com when setting up their environment
  • Automatic type inference (similiar to dynamic languages, var x int =3 or x := 3 or y := “James” are all valid)
  • Automatic documentation. Like JDoc or PHPDoc, but no comments required, and even no commands. You can automatically have your code documented at the same level of quality as the standard library and inbuilt golang API’s.
  • Strict compilation checking, unused packages and variables will prevent compilation.
  • Strong standard library
  • Awesome at building API’s/backend
  • Cross platform (runs on linux/mac/windows. Currently has experimental mobile support. You can write an opengl program that can run on iOS/Android natively in Go1.5).
  • Useful tools for code linting, code generation, building, testing, etc.

What Go doesn’t have:

  • Classes ( * SHOCKED EXPRESSION *) — Golang has Structs, and struct functions, but there is deliberately no tradtional class structure or inheritance. Objects follow an Interface simply by having the correct function
  • Generics. This is divisive to newcomers, but decisions made to build fast and smart binaries, no generic functions exist. This means if you have an getArea(number) function, you must have a getFloatArea(float) and getIntArea(int) if you wish to cover multipe types. Note that interfaces will allow alternatives to sidestep this issue with still some extra code but better organsation.
  • Full memory control (due to garbage collection system)
  • Vendoring is still early and can be enabled via an experimental flag. You can pull packages but updating them independantly; there are some community tools but I would expect something like a package.json to be added in the next release of Golang.

Why should developers care about Golang?

  • Golang combines a clean, fast, typed language that is particularly strong for web development and has built into its ethos and community one very clear message: You don’t need a web development framework! The standard library provides everything you need to build a web server, do routing, html templates, file serving, res/req handling, databases, etc..
  • It is very opinionated about how code should be written. For example the default linting tool decides exactly where there should be new lines (no more than one additional between function, etc.), automatically formatting brackets; code will not execute if you start your curly brace on a new line, there are no semi-colons due to the insistence on this rule. This means code is very readable, code can be easily worked on between teams and people can easily move between projects and be effective.
  • Compilation is very fast (usually a second or two), and produces a single binary. This means in terms of artefact handling for deployment you only need to push a new binary and run it. There are currently MANY tools to enable application server orchestration (Puppet, Docker and the like), because a traditional Java Application might take someone half a day to setup just to run a hello world on a server. When Atlassian can to talk to us about how Docker enables their developers to setup their code in an hour instead of a day or two, this to me speaks to how languages like Java which is common in many places for reliable web app’s and API builds have some many pieces holding it together to be able to run. The web server, the build tool, the framework, the framework build tools, the dozens of libraries available to get core usage of the tools, testing tools… You’re getting a picture here. It’s big, i’ts clunky and we’re investing huge amounts of effort into learning orchestration tools because the fundamental tools we’re using to code and build web apps and api’s are crap.
  • Whilst “The Cloud” has enabled us to quickly build, clone and dynamically add servers to handle load of performant web applications, it often ends up with people horizontally scaling to cater for often poor performing applications. 10 applications servers to run a simple web app because peak loads require it is a very expensive cost to customers. Using a typed compiled language gives huge benefits in this domain. There’s a great article from the creators of Parse, the mobile backend api tool about how moving from ruby to let them reduce their API server pool down by 90%, which is definitely worth reading here.
  • Concurrency is baked nicely into the language. Go has has the very simple ‘go’ keyword, which is to say “go do this function in the background”, channels, which allow for buffered references of data for processing as well as parallelism by running go-routines on multiple cores asynchronously. These tools are not libraries or packages but instead primitives in the flow of the language/compiler. This means developers can write programs that with relatively little easy take full use of the CPU available and build non blocking, beautiful programs.
  • It’s open source and encourages all code and libraries built to solve problems to be part of the open source community. This would provide an opportunity to make some excellent tools and libraries that could be shared with the larger software development community.
  • Golang is currently the goto programming language for dev ops development. It’s what Docker was built in. If we wish to not just support dev ops for clients but continue building tools that are flexible and usable for the larger dev ops community, Golang is an excellent language for doing so.
  • Mobile is still in its experimental phase, but you can currently build OpenGL applications with Golang that run on both iOS and Android as well as include callable binaries for running shared code/business logic on both platforms. There is currently no UI binding to UIKit or the Android interface builder, but I think it’ll be coming, at least for android. It wouldn’t surprise me if the next 18 months Google push it as the next language for building native android mobile apps, in the same way apple have transitioned to Swift as it’s future language moving forward.

What has my experience been like?

GoPath + Setup

Go-Sublime with organised imports

Compiling Code

Writing Code

Closing Thoughts

  1. Getting Started, official golang page — https://golang.org/doc/
  2. Parse’s move from Ruby to Golang — http://blog.parse.com/learn/how-we-moved-our-api-from-ruby-to-go-and-saved-our-sanity/
  3. Tutorial — Creating a Wiki — https://golang.org/doc/articles/wiki/ (this was the first big tutorial that got me to build something useful, take this one slow to get a grasps on its concepts)
  4. Golang — Concurrency is not Parallelism (Rob Pike), this video I found super informative about go’s concurency and got me excited to keep coding in Golang — https://youtu.be/cN_DpYBzKso

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
James O'Toole

James O'Toole

More from Medium

Getting started with GO Programming Language — Part Two

Details of Go JSON serialization of []byte type

[golang] How to use github for hosting self-updating binaries for your golang projects

JSON Unmarshal interface values in Go