How to Troubleshoot Apps for the Modern Connected Worker
Ready, set, go! An introduction to the Go programming language
1. Ready, Set, GO!
Chad McCallum
ASP.NET MVP
iQmetrix Software
www.rtigger.com - @ChadEmm
An Introduction to the Go Programming
Language
2. What is Go?
A programming language!
Initially created as a Google 20% project
Released as an open source project on November
10th, 2009
Go 1 (version 1) released on March 28th, 2012
3. The Software Development Landscape
Born out of frustration with current languages
There was a choice between efficient compilation, efficient execution, or
ease of programming – most languages didn’t offer all three
Computers are faster, but software development isn’t
Dependency management is an unnecessarily large, complex part of
software development
The complexity and awkwardness of type systems are losing out to
languages like Python and JavaScript
Old languages haven’t caught up to modern affordances, like garbage
collection and parallel computation
Multicore programming is scary and worrysome
4. Enter Go
Possible to compile a large program in a few seconds on a
single computer
Provides a dependency model that avoids the overhead of
traditional systems
The type system has no hierarchy, so no time is lost
defining relationships
Fully garbage collected and provides primitives for
concurrent execution and communication
By design, offers an approach to system software on
multicore machines
5. A Review of Go’s Features
Simple language specification
Compiles statically linked binaries without external
dependencies
Remote package management
Concurrency primitives
6. Simple Language Specification
“Language specification simple enough to keep in a
programmer’s head”
No type inheritance (uses duck typing)
No method or operator overloading
No pointer math
No assertions
No generic programming
7. Statically Linked Binaries
Compiles to native machine code (x86 and ARM)
All referenced libraries are compiled into the same binary
– no need to install libraries or framework on target
machine
Because there’s no intermediate language, interpreter, or
framework, applications start and run with minimal
overhead
8. Remote Package Management
Can import dependencies directly from remote
repositories, like GitHub, BitBucket, Google Code
go get github.com/ChadMcCallum/gotest
Uses the current version of the code in “master” (git) or “default”
(mercurial)
Downloaded to local GOPATH folder
9. Concurrency Primitives
goroutine – executes function on a lightweight process
Similar to task pools in .NET, functions are executed on any
available thread allocated by the application
Ensures routines don’t block each other
Allows developers to write synchronous code while being fully non-
blocking
Channels provide a way to read and write between
routines without managing synchronization
A routine that writes to a channel will wait until its message is
received
A routine that reads from a channel will wait until it receives a
message
10. Why Choose Go?
Why choose any language?
Popularity – is there a decent amount of community support?
Language-domain match – is the strengths of the language geared
towards your problem domain?
Libraries – what packages already exist that you can reuse?
Efficiency – does the compiler and execution match up with your
project’s requirements?
Tools – do the appropriate coding, debugging, tracing, and testing
tools exist?
11. Popularity
Currently 36th on the TIOBE Index (March 2014)
Used in a number of large projects at Google
Youtube.com, dl.google.com, Google App Engine
Used in a number of production systems
Bit.ly, Torbit, pool.ntp.org, Canonical, CloudFlare, Conformal, Nov
artis, BBC, SoundCloud, Moovweb, Heroku, Nokia
4472 questions in StackOverflow
16681 topics on the golang-nuts group
12. Language-Domain Match
Targeted at systems programming
Strengths in concurrency and deployment model
Mostly used in server and message-processing scenarios
Can, and does, support other scenarios
Web apps, games, graphical tools, education
14. Efficiency
Natively compiled binaries
Not interpreted
No external dependencies
No Intermediate Language, Common Language Runtime, or
Virtual Machine
Calculating 8 primes in parallel
.NET Tasks – 12.6 seconds Goroutines – 5.99 seconds
15. Tools
go build – compiles packages and dependencies into
executable
go fix – rewrites programs that use old APIs to use the
newest version
go fmt – changes source code to match go standard
go get – download and install packages and dependencies
go install – compile and install packages and dependencies
go run – compile and run program
go test – run tests in packages
16. IDEs
LiteIDE – cross-platform IDE with support for Go and
Markdown
Go plugin for Eclipse (Goclipse) – plugin for Eclipse
Zeus – Windows-only IDE with Go support
All three offer debugging, syntax highlighting, and code
completion