17
Ready, Set, GO! Chad McCallum ASP.NET MVP iQmetrix Software www.rtigger.com - @ChadEmm An Introduction to the Go Programming Language

Ready, set, go! An introduction to the Go programming language

  • Upload
    rtigger

  • View
    735

  • Download
    1

Embed Size (px)

DESCRIPTION

A brief primer on Go - it's origins, its features, and why you may want to use it in your next software project

Citation preview

Page 1: Ready, set, go! An introduction to the Go programming language

Ready, Set, GO!

Chad McCallumASP.NET MVP

iQmetrix Softwarewww.rtigger.com - @ChadEmm

An Introduction to the Go Programming Language

Page 2: Ready, set, go! An introduction to the Go programming language

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

Page 3: Ready, set, go! An introduction to the Go programming language

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

Page 4: Ready, set, go! An introduction to the Go programming language

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

Page 5: Ready, set, go! An introduction to the Go programming language

A Review of Go’s Features

Simple language specification Compiles statically linked binaries without external

dependencies Remote package management Concurrency primitives

Page 6: Ready, set, go! An introduction to the Go programming language

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

Page 7: Ready, set, go! An introduction to the Go programming language

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

Page 8: Ready, set, go! An introduction to the Go programming language

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

Page 9: Ready, set, go! An introduction to the Go programming language

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

Page 10: Ready, set, go! An introduction to the Go programming language

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?

Page 11: Ready, set, go! An introduction to the Go programming language

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, Novartis, BBC, SoundCloud, Moovweb, Heroku, Nokia

4472 questions in StackOverflow 16681 topics on the golang-nuts group

Page 12: Ready, set, go! An introduction to the Go programming language

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

Page 13: Ready, set, go! An introduction to the Go programming language

Libraries

25,522 repositories on GitHub

Application containers,

web frameworks,

websockets,

continuous integration,

shared key-value stores,

shared cache,

distributed messaging,

maching imaging,

SQL engines,

service orchestration,

client code generation,

analytics,

autocomplete,

load testing,

http traffic capture,

static site generation,

geolocation,

PaaS

Page 14: Ready, set, go! An introduction to the Go programming language

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

Page 15: Ready, set, go! An introduction to the Go programming language

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

Page 16: Ready, set, go! An introduction to the Go programming language

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

Page 17: Ready, set, go! An introduction to the Go programming language

Ready, Set, GO!

golang.org tour.golang.org play.golang.org godoc.org gobyexample.com goinggo.net

Chad McCallum@ChadEmm

www.rtigger.com