Xuebin He
Xuebin He
Golang EMC Dojo
1
Xuebin HeXuebin He
play.golang.org
github.com/kaleo211/golang-demo
Xuebin He
Origins
3
Xuebin He
❖ Created at Google in 2007
❖ Open Source in 2009
❖ First stable release in 2012
4
Xuebin He 5
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
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)) }
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
Xuebin He
Why Go?
Xuebin HeXuebin He
Fast Compilation Easy for OOP
Built-in Concurrency Pass by Reference
Readability Dependency Management
Xuebin HeXuebin He
Fast Compilation Easy for OOP
Built-in Concurrency Pass by Reference
Readability Dependency Management
Xuebin He
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.”
Xuebin HeXuebin He
Fast Compilation Easy for OOP
Built-in Concurrency Pass by Reference
Readability Dependency Management
Xuebin HeXuebin He
Xuebin He
Xuebin He
“If you could do Java over again,
what would you change?”
Xuebin He
“The real problem wasn't classes, but rather implementation inheritance.”
“I’d leave out classes.”
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
Xuebin He
Duck Typing
“If it looks like a duck and quacks like a duck, it’s a duck.”
Xuebin HeXuebin He
Xuebin HeXuebin He
Fast Compilation Easy for OOP
Built-in Concurrency Pass by Reference
Readability Dependency Management
Xuebin HeXuebin He
Concurrency vs Parallelism
Dealing with things at once Doing things at once
Core0
Core1Core0
Xuebin HeXuebin He
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
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
Xuebin HeXuebin He
Fast Compilation Easy for OOP
Built-in Concurrency Pass by Reference
Readability Dependency Management
Xuebin He
Pass by Value vs Pass by Reference
Performance
Xuebin HeXuebin He
Pointer Arithmetic
Memory allocation
Segment Error
Xuebin HeXuebin He
Fast Compilation Easy for OOP
Built-in Concurrency Pass by Reference
Readability Dependency Management
Xuebin HeXuebin He
60+ companies
3,000,000 lines
Xuebin He
VS
Xuebin HeXuebin He
go fmt
Xuebin HeXuebin He
Fast Compilation Easy for OOP
Built-in Concurrency Pass by Reference
Readability Dependency Management
Xuebin HeXuebin He
gocode├── bin├── pkg└── src ├── github.com │ ├── Sirupsen │ │ └── logrus │ ├── kaleo211 │ │ └── golang-demo │ └── kisielk │ ├── errcheck │ └── gotool └── golang.org └── x ├── net └── oauth2
Xuebin HeXuebin He
go get github.com/kaleo211/golang-demo