29
Introduction to Go AND WHY IT’S AWESOME

Introduction to go, and why it's awesome

Embed Size (px)

Citation preview

Introduction to GoAND WHY IT’S AWESOME

About meSWE at Google

Open source

Kubernetes written in Go

https://github.com/kubernetes/kubernetes

Today you’ll learnWhat is Go?

Why Go?

Basic Syntax

Features

A little background about Go...

HistoryStarted at Google

Released, open-sourced in 2009

New, modern

20161945

C

1972

Python

1991

JavaJavaScript

1995

Go

2009

https://golang.org/

Why Go?Google internal needs

★ Efficient large scale programming★ Distributed systems★ Speed of compilation★ Multicore, networked hardware

http://xkcd.com/

Go is… Fast compilation time

Concurrent

Garbage-collected

Modern with support for networked and multi-core computing

General-purpose

Compiled

Statically typed like C, Java

Feels as easy, lightweight as JS, Python

Design PrinciplesSimplicity concepts easy to understand

Orthogonality concepts mix cleanly

Readability comprehensible with little context

Companies Using Go

http://stackshare.io/go/in-stacks

Some basic syntax

Hello World

Functions

Object-oriented?

Yes and no...Composition over inheritance

★ No type hierarchy ★ No class★ No generics

Simple Type SystemStatically typed, with type inference

Types and methodsYou can define methods on any type I mean ANY

InterfacesAn interface type defines a set of methods

More on Go features

ConcurrencyUNIX: processes connected by pipes

$ find ~/go/src/pkg | grep _test.go$ | xargs wc -l

Go: goroutines connected by channels, concurrency made easy to use

Concurrency: goroutinesLightweight threads

Concurrency: channelsChannels are a typed pipe for★ Synchronization★ Communication

Concurrency philosophy The efficiency of an asynchronous model written in a synchronous style

Connect goroutines with channels -- simpler, maintainable code

Toolinggofmt reformats code

goimports updates import lines

golint prints style mistakes

godoc documentation of packages and symbols

go vet vets the package

go get download and install packages and dependencies

go test automates testing the packages

no more tabs vs. spaces!

no more “import not used”, or “import not found”

Rich library supportComprehensive standard library

150+ packages

Many great external libraries

120, 000+ packages

https://godoc.org/

What’s Go good for?

Go: a general-purpose languageNot just a “systems language”

Unexpected interest from users of scripting languages

Diverse uses across the community

★ Scientific computing★ Web applications★ Graphics and sound★ Network tools★ … and much more

Demo: a simple web app

Recap: Go isFast compilation time

Concurrent

Garbage-collected

Modern with support for networked and multi-core computing

General-purpose

Compiled

Statically typed like C, Java

Feels as easy, lightweight as JS, Python

What’s nextA Tour of Go tour.golang.org

The Go Playground play.golang.org

Documentation golang.org/doc

Go Wiki github.com/golang/go/wiki

https://golang.org/