introduction to go

73
An Introduction to Go given January 30, 2014 at CodeFellows Zack Hubert

Upload: zhubert

Post on 01-Jul-2015

356 views

Category:

Technology


1 download

DESCRIPTION

Slides from a talk I gave at CodeFellows in January 2014

TRANSCRIPT

Page 1: Introduction to Go

!

An Introduction to Gogiven January 30, 2014 at CodeFellows

Zack Hubert

Page 2: Introduction to Go

Hi, I’m Zack

Page 3: Introduction to Go

I work here…and…

Page 4: Introduction to Go

I think Go is Awesome

Page 5: Introduction to Go

I think you’ll like it too

Page 6: Introduction to Go

My Story with Go

Page 7: Introduction to Go

The Year was 2012

• It was a NEW PROJECT!

• Make it Real Time

• Use a Javascript MVC

Page 8: Introduction to Go

Ruby on RailsServer side choice was easy…

Page 9: Introduction to Go

What about the Client Side?

Page 10: Introduction to Go

logos believed to be fair use

Page 11: Introduction to Go

Batman.jsHas been a great choice

Page 12: Introduction to Go

What kind of product?Resource Scheduling

Page 13: Introduction to Go

–Our Customers

“For an event that occurs weekly from 7-9pm on Wednesdays, Fridays (except 3 weeks...) are five out of ten chairs available along with three tables to go in the Green room and

make sure Bill approves?”

Page 14: Introduction to Go

Rails Performance

< 150ms? This could be a problem.

Page 15: Introduction to Go

SolutionMySQL Upserts

Histogram the Schedule Heavily Precompute Values in Cache

Page 16: Introduction to Go

It Worked!

Page 17: Introduction to Go

The Good

• 40ms

• Rails+MySQL

• No NoSQL

• Same stack as other apps

Page 18: Introduction to Go

The Bad

• Millions of rows of computed values

• Caching is error prone

• Data model polluted with derivative classes

Page 19: Introduction to Go

Free Week - 2012

• Looked at Go for an API

• Didn’t understand it

• Frustrated by many things

• Compiler error on unused import…wha!?

Page 20: Introduction to Go

Go is Opinionatedfrustration will ensue without knowing the opinions of

the designers

Page 21: Introduction to Go

Back to Resources

• 1.5 years later…many users etc.

• The app was getting slower (larger JSON responses)

• Complexity was an increasing burden

Page 22: Introduction to Go

Techempower JSON encoding benchmark

http://www.techempower.com/benchmarks bottom is visible :(

Page 23: Introduction to Go

Free Week - 2013

• Had been reading up in the intervening year

• Watched every video I could

• and then it made sense…

Page 24: Introduction to Go

RUSH is Born• Resource Utilization Service Handler

• Day 1 - Working Service

• Day 2 - Accurate Service

• Week 1 - Production Ready

• Launched Post Holidays

• Rock solid.

• (word play on my favorite band)

Page 25: Introduction to Go

RUSH Performance

• 100x faster than the heavily cached Ruby option

• 1,000x faster than Ruby without caching

• 1% of the memory footprint

Page 26: Introduction to Go
Page 27: Introduction to Go

Go turns out to be the best at JSON

…a perfect complement, huzzah :)

Page 28: Introduction to Go

Why Learn Go?

Page 29: Introduction to Go

Why Learn Go?

• Crazy fast

• Awesome complement to JS MVC

• Great service carveout to help an interpreted language web framework like Ruby on Rails

Page 30: Introduction to Go

FUN!

Page 31: Introduction to Go

Overview

• A brief history of Go

• Language design decisions

Page 32: Introduction to Go

What is Go?Go is a new, general-purpose programming language.

Page 33: Introduction to Go

What is Go?• Compiled: compiler makes

runnable binary

• Statically typed: compiler checks for a category of mistakes

• Concurrent: easy composition of processes, (may be simultaneously executed)

• Garbage Collected: runtime release of no longer used memory

• Simple: as classically defined :)

Page 34: Introduction to Go

The Story of Go

Page 35: Introduction to Go

Rob PikeBell Labs

Unix team created Plan 9/Inferno os co-author with Kernighan

(Unix Programming Environment)

co-creator of UTF-8 (with Ken)

image cc by-sa 3.0 chlor at en.wikipedia.org

Page 36: Introduction to Go

Ken Thompson (seated)designed UNIX, B, Plan 9, Turing award

image cc by-sa 2.0 at en.wikipedia.org

Page 37: Introduction to Go

Robert Griesemer

V8, Chubby for GFS, Java HotSpot VM, compiler for Cray Y-MP, interpreter for

APL

image cc by-sa 3.0 at en.wikipedia.org

Page 38: Introduction to Go

The Creation Storylong C++ build, 45 minutes, whiteboarded the language

image still from Google I/O 2012

Page 39: Introduction to Go

Open Sourced Nov, 2009464 contributors as of January 26, 2014

Page 40: Introduction to Go

Already Quite Popular(SO vs Github)

Page 41: Introduction to Go

Problem #1: Development Speed

Page 42: Introduction to Go

Development Speed

• “It's a fast statically typed compiled language that feels like a dynamically typed interpreted language.” - golang.org

Page 43: Introduction to Go

Fast is FUN

Page 44: Introduction to Go

Fast has its Tradeoffs

“Missing” language features - Generics, Inheritance, etc.

Page 45: Introduction to Go

and its quirksmanaged imports for instance…but it makes sense

from the creation

Page 46: Introduction to Go

Problem #2: Make it Modern

Page 47: Introduction to Go

Age of Languages?

Page 48: Introduction to Go

C++ 1979

Page 49: Introduction to Go

Python 1989

Page 50: Introduction to Go

Java 1990

Page 51: Introduction to Go

Ruby 1993

Page 52: Introduction to Go

Go - 2007(14 years after Ruby)

Page 53: Introduction to Go

Modern Means Multicore

Page 54: Introduction to Go

Multicore/Concurrency• Concurrency through CSP-

style processes called go routines

• 1978 CSP by Sir Tony Hoare

• M:N runtime mapping of green threads to system threads

• “Do not communicate by sharing memory, instead share memory by communicating” - Pike

image by Rama cc by-sa 2.0-fr at en.wikipedia.org

Page 55: Introduction to Go

Concurrency is HUGE in Go

Page 56: Introduction to Go

Modern Means Internetit’s kind of a big deal

Page 57: Introduction to Go

The Internet Age

• Go ships with a “batteries included” standard library

• For instance, net/http

• Instead of frameworks to pick up the slack, the std-lib has most of what you need

Page 58: Introduction to Go

Problem #3: Complexity

Page 59: Introduction to Go

Webscale.large programs, big teams.

Page 60: Introduction to Go

Seriously though…

• Designed to be C-like for early career programmers

• Simplified syntax

Page 61: Introduction to Go

1 keyword for looping

Simple

Page 62: Introduction to Go

Garbage CollectionSimple, easier with concurrency

Page 63: Introduction to Go

25 keywords total50 in Java, 48 in C++, ~42 in Ruby

Page 64: Introduction to Go

No InheritanceComposition is easier to get right, defers design

decisions

Page 65: Introduction to Go

CSP ConcurrencyMutexes are hard to get right. Channels are easier.

Page 66: Introduction to Go

So…when Go is confusing ask…

Page 67: Introduction to Go

Is this because the language is YOUNG?

Page 68: Introduction to Go

Is this because it’s SIMPLE?

Page 69: Introduction to Go

Is this because it wants to be FAST?

Page 70: Introduction to Go

Revised…Original talk proceeded to 1 hour Tour of Go

and then “The Fun Part” (hands-on with Go, using D&D imagery)

Page 71: Introduction to Go

Keep on Learnin’

• http://golang.org

• http://gobyexample.org

• http://gophercasts.io

Page 72: Introduction to Go

Thank You!@zhubert, http://www.zhubert.com

Page 73: Introduction to Go

Let’s Have Some Questions