EMC Dojo Golang Meetup Cambridge

36
Xuebin He Xuebin He Golang EMC Dojo 1

Transcript of EMC Dojo Golang Meetup Cambridge

Page 1: EMC Dojo Golang Meetup Cambridge

Xuebin He

Xuebin He

Golang EMC Dojo

1

Page 2: EMC Dojo Golang Meetup Cambridge

Xuebin HeXuebin He

play.golang.org

github.com/kaleo211/golang-demo

Page 3: EMC Dojo Golang Meetup Cambridge

Xuebin He

Origins

3

Page 4: EMC Dojo Golang Meetup Cambridge

Xuebin He

❖ Created at Google in 2007

❖ Open Source in 2009

❖ First stable release in 2012

4

Page 5: EMC Dojo Golang Meetup Cambridge

Xuebin He 5

Page 6: EMC Dojo Golang Meetup Cambridge

Xuebin He

❖ C: syntax, control-flow, basic data types, call by value, pointers

❖ Oberon-2: packages, imports, method declarations

❖ Alef: concurrency, channel, garbage collection

6

Page 7: EMC Dojo Golang Meetup Cambridge

Xuebin HeXuebin He

package main

/* #include <stdio.h> #include <stdlib.h>

void myprint(char* s) { printf("%s\n", s); } */ import "C" import "unsafe"

func main() { cs := C.CString("Hello from stdio\n") C.myprint(cs) C.free(unsafe.Pointer(cs)) }

Page 8: EMC Dojo Golang Meetup Cambridge

Xuebin He

TIOBE for June 2016

Position Language Ratings

1 Java 20.794%

2 C 12.376%

3 C++ 6.199%

4 Python 3.900%

40 Go 0.209%

8

Page 9: EMC Dojo Golang Meetup Cambridge

Xuebin He

Why Go?

Page 10: EMC Dojo Golang Meetup Cambridge

Xuebin HeXuebin He

Fast Compilation Easy for OOP

Built-in Concurrency Pass by Reference

Readability Dependency Management

Page 11: EMC Dojo Golang Meetup Cambridge

Xuebin HeXuebin He

Fast Compilation Easy for OOP

Built-in Concurrency Pass by Reference

Readability Dependency Management

Page 12: EMC Dojo Golang Meetup Cambridge

Xuebin He

Page 13: EMC Dojo Golang Meetup Cambridge

Xuebin He

“Go provides a model for software construction that

makes dependency analysis easy and avoids much of

the overhead of C-style include files and libraries.”

Page 14: EMC Dojo Golang Meetup Cambridge

Xuebin HeXuebin He

Fast Compilation Easy for OOP

Built-in Concurrency Pass by Reference

Readability Dependency Management

Page 15: EMC Dojo Golang Meetup Cambridge

Xuebin HeXuebin He

Page 16: EMC Dojo Golang Meetup Cambridge

Xuebin He

Page 17: EMC Dojo Golang Meetup Cambridge

Xuebin He

“If you could do Java over again,

what would you change?”

Page 18: EMC Dojo Golang Meetup Cambridge

Xuebin He

“The real problem wasn't classes, but rather implementation inheritance.”

“I’d leave out classes.”

Page 19: EMC Dojo Golang Meetup Cambridge

Xuebin He

Is-a vs Has-a

Prius is a car that has the ability to run

Peter has the ability to run

Peter is a human that has the ability to run

Page 20: EMC Dojo Golang Meetup Cambridge

Xuebin He

Duck Typing

“If it looks like a duck and quacks like a duck, it’s a duck.”

Page 21: EMC Dojo Golang Meetup Cambridge

Xuebin HeXuebin He

Page 22: EMC Dojo Golang Meetup Cambridge

Xuebin HeXuebin He

Fast Compilation Easy for OOP

Built-in Concurrency Pass by Reference

Readability Dependency Management

Page 23: EMC Dojo Golang Meetup Cambridge

Xuebin HeXuebin He

Concurrency vs Parallelism

Dealing with things at once Doing things at once

Core0

Core1Core0

Page 24: EMC Dojo Golang Meetup Cambridge

Xuebin HeXuebin He

Page 25: EMC Dojo Golang Meetup Cambridge

Xuebin He

Goroutines vs Thread

The OS schedules threads to run against available processors

Go runtime schedules goroutines to run within a logical processor that is bound to a single OS thread

Page 26: EMC Dojo Golang Meetup Cambridge

Xuebin HeXuebin He

Go 1.6.2 (April 2016) 64-bit x86 CPU (A10-7850K 4GHz) | Number of goroutines: 100,000 | Per goroutine: | Memory: 4707.92 bytes | Time: 1.842097 µs

Page 27: EMC Dojo Golang Meetup Cambridge

Xuebin HeXuebin He

Fast Compilation Easy for OOP

Built-in Concurrency Pass by Reference

Readability Dependency Management

Page 28: EMC Dojo Golang Meetup Cambridge

Xuebin He

Pass by Value vs Pass by Reference

Performance

Page 29: EMC Dojo Golang Meetup Cambridge

Xuebin HeXuebin He

Pointer Arithmetic

Memory allocation

Segment Error

Page 30: EMC Dojo Golang Meetup Cambridge

Xuebin HeXuebin He

Fast Compilation Easy for OOP

Built-in Concurrency Pass by Reference

Readability Dependency Management

Page 31: EMC Dojo Golang Meetup Cambridge

Xuebin HeXuebin He

60+ companies

3,000,000 lines

Page 32: EMC Dojo Golang Meetup Cambridge

Xuebin He

VS

Page 33: EMC Dojo Golang Meetup Cambridge

Xuebin HeXuebin He

go fmt

Page 34: EMC Dojo Golang Meetup Cambridge

Xuebin HeXuebin He

Fast Compilation Easy for OOP

Built-in Concurrency Pass by Reference

Readability Dependency Management

Page 35: EMC Dojo Golang Meetup Cambridge

Xuebin HeXuebin He

gocode├── bin├── pkg└── src ├── github.com │   ├── Sirupsen │   │   └── logrus │   ├── kaleo211 │   │   └── golang-demo │   └── kisielk │      ├── errcheck │      └── gotool └── golang.org    └── x   ├── net    └── oauth2

Page 36: EMC Dojo Golang Meetup Cambridge

Xuebin HeXuebin He

go get github.com/kaleo211/golang-demo