Go is your friend

48
ROME April 11-12th 2014 Go is your friend Gianfranco Reppucci Lead Developer at Qurami giefferre

description

Go, also called golang, is a programming language developed at Google in 2007 and publicly released in 2009. Combined with App Engine AND the AngularJS framework, golang represents the backend solution which completes Google's "developer suite". In spite of its youth, it includes a bunch of powerful features with a low learning curve and great performances, for any desktop platform.

Transcript of Go is your friend

Page 1: Go is your friend

ROME April 11-12th 2014

Go is your friend

Gianfranco Reppucci Lead Developer at Qurami

giefferre

Page 2: Go is your friend

ROME April 11-12th 2014 - Gianfranco Reppucci

About me

Page 3: Go is your friend

ROME April 11-12th 2014 - Gianfranco Reppucci

Page 4: Go is your friend

ROME April 11-12th 2014 - Gianfranco Reppucci

Evolution

As developers, we’ve changed a lot since a decade ago

Page 5: Go is your friend

ROME April 11-12th 2014 - Gianfranco Reppucci

Evolution

• Monolithic, 100% custom code • Super-complete, MVC frameworks

with tons of built-in features • Simple, bootstrapping frameworks

w/ dependency managers

Page 6: Go is your friend

ROME April 11-12th 2014 - Gianfranco Reppucci

Context

• There is a lot of different languages available to developers • Some of them are pretty easy, some

others have great performances • We can find frameworks and plugins for

each of them

Page 7: Go is your friend

ROME April 11-12th 2014 - Gianfranco Reppucci

The big dilemma

I’m starting a new project. Which technology do you think I should use?

Page 8: Go is your friend

ROME April 11-12th 2014 - Gianfranco Reppucci

There’s no right choice

As developers: • A great idea can be built with

(perhaps) any language • Pros and cons are everywhere • You’ll pay a certain price for whatever

advantages you could have

Page 9: Go is your friend

ROME April 11-12th 2014 - Gianfranco Reppucci

There’s no right choice

As entrepreneurs: • When choosing a specific technology,

you’ll probably need to justify the decision to yourself, your partners and investors

• Decisions would be based on company’s vision

Page 10: Go is your friend

ROME April 11-12th 2014 - Gianfranco Reppucci

Start usingsomething modern

Go is an open source programming language that makes it easy to build simple,

reliable and efficient software.

quote from golang.org

Page 11: Go is your friend

ROME April 11-12th 2014 - Gianfranco Reppucci

What Go is:

• Open source BSD licensed project • Language specification • Runtime components

(garbage collector, scheduler, etc) • Two different compilers (gc or gccgo) • Standard libraries • Documentation

Page 12: Go is your friend

ROME April 11-12th 2014 - Gianfranco Reppucci

History

• Developed at Google in 2007 as an experiment • Publicly announced in 2009 • Integrated in App Engine in 2011

Page 13: Go is your friend

ROME April 11-12th 2014 - Gianfranco Reppucci

Who is using Go?

Page 14: Go is your friend

ROME April 11-12th 2014 - Gianfranco Reppucci

Who is using Go?

Page 15: Go is your friend

ROME April 11-12th 2014 - Gianfranco Reppucci

A modern C

Go sits somewhere between C and Python. !

It has the static type checking and bit-twiddling powers of C, yet much of the speed of development and conciseness of Python.

quote from Graham King

Page 16: Go is your friend

ROME April 11-12th 2014 - Gianfranco Reppucci

Absolutely genuine

• No class inheritance • No method or operator overloading • No circular dependencies among packages • No generic programming • No assertions • No pointer arithmetic

Page 17: Go is your friend

ROME April 11-12th 2014 - Gianfranco Reppucci

Performance driven

Built-in concurrency primitives: • light-weight threads, called goroutines • channels • select statements

Page 18: Go is your friend

ROME April 11-12th 2014 - Gianfranco Reppucci

I mean, seriously

Page 19: Go is your friend

ROME April 11-12th 2014 - Gianfranco Reppucci

I mean, seriously

Page 20: Go is your friend

ROME April 11-12th 2014 - Gianfranco Reppucci

I mean, seriously

Page 21: Go is your friend

ROME April 11-12th 2014 - Gianfranco Reppucci

Does God exist?

• If you have doubts or issues when styling your Go code, you can use gofmt • gofmt’s aim is to format Go files,

returning a valid and “beautified” version of the code

Page 22: Go is your friend

ROME April 11-12th 2014 - Gianfranco Reppucci

A little bit of code

Page 23: Go is your friend

ROME April 11-12th 2014 - Gianfranco Reppucci

Object Oriented Go

Page 24: Go is your friend

ROME April 11-12th 2014 - Gianfranco Reppucci

A type declaration

! type Name struct {!! ! First string!! ! Middle string!! ! Last string!! }

Page 25: Go is your friend

ROME April 11-12th 2014 - Gianfranco Reppucci

A method declaration

! func (n Name) String() string {!

! ! return fmt.Sprintf(!

! ! ! “%s %c. %s”,!

! ! ! n.First,!

! ! ! n.Middle[0],!

! ! ! n.Last,!

! ! )!

! }

Page 26: Go is your friend

ROME April 11-12th 2014 - Gianfranco Reppucci

Instancing a Name

! aName := Name{“John”, “Go”, “White”}!!! fmt.Println(aName.String())

Page 27: Go is your friend

ROME April 11-12th 2014 - Gianfranco Reppucci

Goroutines

Page 28: Go is your friend

ROME April 11-12th 2014 - Gianfranco Reppucci

Given the yell function

func yell(word string, seconds int) {!

! time.Sleep(time.Duration(seconds) * time.Second)!

! fmt.Println(word)!

}

Page 29: Go is your friend

ROME April 11-12th 2014 - Gianfranco Reppucci

Guess what’s the output

func main() {!! go yell(“2014”, 5)!! go yell(“Codemotion”, 1)!! go yell(“Roma”, 4)!! time.Sleep(10 * time.Second)! }

Page 30: Go is your friend

ROME April 11-12th 2014 - Gianfranco Reppucci

Channels

Page 31: Go is your friend

ROME April 11-12th 2014 - Gianfranco Reppucci

Channels

• Implement parallelism and synchronization • Channels can be of any type of data

structure, even custom structs • Can be buffered or unbuffered

Page 32: Go is your friend

ROME April 11-12th 2014 - Gianfranco Reppucci

An example

c := make(chan int)!

! go func() {!

! list.Sort()!

! c <- 1!

}()!

! doSomethingForAWhile()!

<-c

Page 33: Go is your friend

ROME April 11-12th 2014 - Gianfranco Reppucci

Select statement

Page 34: Go is your friend

ROME April 11-12th 2014 - Gianfranco Reppucci

Select

The select statement is like a switch, but it selects over channel operations andchooses exactly one of them

Page 35: Go is your friend

ROME April 11-12th 2014 - Gianfranco Reppucci

An example ticker := time.NewTicker(250 * time.Millisecond)! boom := time.After(1 * time.Second)!! for {!! select {!! ! case <- ticker.C:!! ! ! fmt.Println(“tick”)!! ! case <- boom:!! ! ! fmt.Println(“BOOM!”)!! ! ! return!! }! }

Page 36: Go is your friend

ROME April 11-12th 2014 - Gianfranco Reppucci

Start writing yourGo code now

Open your browser and point it to

http://tour.golang.org

for a quick tour, or

http://play.golang.org

to test your own snippets online

Page 37: Go is your friend

ROME April 11-12th 2014 - Gianfranco Reppucci

Why should I use Go?

• Syntax and environments are similar to dynamic languages • Simple language specification • Powerful and lightweight

Page 38: Go is your friend

ROME April 11-12th 2014 - Gianfranco Reppucci

Why should I use Go?

• Full development environment (doc, dependencies, formatter, tests) • Static compilation

with NO dependencies binary output • Multi environment build

Page 39: Go is your friend

ROME April 11-12th 2014 - Gianfranco Reppucci

So, what’s Go about?

Page 40: Go is your friend

ROME April 11-12th 2014 - Gianfranco Reppucci

Composition

• Go is Object Oriented, BUT not in the usual way! • Simple data models, simple interfaces

Page 41: Go is your friend

ROME April 11-12th 2014 - Gianfranco Reppucci

Concurrency

• Easily readable concurrency primitives

Page 42: Go is your friend

ROME April 11-12th 2014 - Gianfranco Reppucci

Gophers

Page 43: Go is your friend

ROME April 11-12th 2014 - Gianfranco Reppucci

Page 44: Go is your friend

ROME April 11-12th 2014 - Gianfranco Reppucci

Join us tonight

GOLANGIT Meetup

18:40 - 19.40

Page 45: Go is your friend

ROME April 11-12th 2014 - Gianfranco Reppucci

Thank you!

Gianfranco Reppucci

giefferre

Page 46: Go is your friend

ROME April 11-12th 2014 - Gianfranco Reppucci

References

• The gopher images were created by Renee French and they are Creative Commons Attribution 3.0 licensed

• What technology should my startup use? by Matt Aimonetti

• Go after four months by Graham King • Golang on Google’s App Engine

Page 47: Go is your friend

ROME April 11-12th 2014 - Gianfranco Reppucci

References

• List of organizations that use Go • The gopher look, a photo by Ken Conley • How we went from 30 servers to 2 by Travis

Reeder • Go after 2 years in production by Travis

Reeder • Computer Language Benchmarks Game

Page 48: Go is your friend

ROME April 11-12th 2014 - Gianfranco Reppucci

References

• Go at Google • Docker and Go: why did we decide to write

docker in Go?