Slide 1

Slide 1 text

Implementing a command line client to GitHub in Go Owen Ou @JingwenOwenOu

Slide 2

Slide 2 text

Agenda • Automating Git/GitHub workflows with gh • Introduction to Go • What I learnt from implementing gh with Go

Slide 3

Slide 3 text

What’s gh? • a command line tool that makes working with GitHub easier • gh pull • gh ci • gh fork • etc.

Slide 4

Slide 4 text

A broken workflow • git checkout -b new_feature • some code changes... • git add . • git commit -m “A comment” • git push origin HEAD • check CI status, oops..context switch • create a pull request, oops...context switch

Slide 5

Slide 5 text

An optimized workflow • git checkout -b new_feature • some code changes... • git add . • git commit -m “A comment” • git push origin HEAD • gh ci # prints build status • gh pull # creates a pull request

Slide 6

Slide 6 text

Demo

Slide 7

Slide 7 text

Implementation of gh • Implemented in Go • Fast (40% faster than Hub) • A single, statically linked binary with no dependencies (no VM needed!) • Unix, e.g., gh pull -b integration -h new_feature

Slide 8

Slide 8 text

What’s Go? • Imperative • Object-oriented like • Concurrent • Compile to machine code • Created at 2009, v1.1.1

Slide 9

Slide 9 text

Ken Thompson • Founding father of Unix, see “Coders at work” • Bring in regular expression to computing • Created grep in an evening • Designed UTF-8 on a diner placemat

Slide 10

Slide 10 text

Robert Griesemer • Native code generation for V8 • Java HotSpot VM • Strongtalk VM (inspires the Dart VM)

Slide 11

Slide 11 text

Rob Pike • First window system for Unix at Bell Labs • Plan 9 • Co-Authors of “The Unix Programming Environment” & “The Practice of Programming” with Brian Kernighan • Newsqueak, Limbo: implementations of Tony Hoare’s CSP

Slide 12

Slide 12 text

Why Go? • Why Learn Go? An interview with Rob Pike: http://www.youtube.com/watch? v=FTl0tl9BGdc

Slide 13

Slide 13 text

Hello Go

Slide 14

Slide 14 text

More about Go • Compilation is very fast, gh has 1581 LOC, the build time is 0.77s • Static typing & type inference • Low level primitives uint, float64 • Garbage collected • Pointers without pointer arithmetic

Slide 15

Slide 15 text

Interfaces

Slide 16

Slide 16 text

The C10K Problem • The problem of optimizing socket server software to handle a large number of clients at the same time • C10k = concurrent ten thousand connections • Linux pthreads (8MB), Windows (1MB), Coroutines (4k, e.g., Ruby Fibers)

Slide 17

Slide 17 text

Goroutines • Coroutines in Go, 4K, light weight threads • Segmented stacks (a double linked lists) • No stack-overflow • Automatically scale to multiple-cores • In the future, scale to multiple machines

Slide 18

Slide 18 text

Goroutines

Slide 19

Slide 19 text

Channels

Slide 20

Slide 20 text

Learning from gh • Right tool for the job - building a Unix tool • Go’s compiler is freaking fast! • Clarity and simplicity, less is more • Go fmt • Fast startup time, low memory usage • Deploy a static library (making deployment so much simpler!) • Goroutines & channels (higher level APIs in net/ http)

Slide 21

Slide 21 text

References • gh: https://github.com/jingweno/gh • Code examples: https://gist.github.com/ jingweno/c00e973ade6d66b827fd • Go at Google: http://www.infoq.com/ presentations/Go-Google • Concurrency is not Parallelism: http:// vimeo.com/49718712 • Real world Go: https://gist.github.com/ ungerik/3731476

Slide 22

Slide 22 text

Q&A