introduction to go
DESCRIPTION
Slides from a talk I gave at CodeFellows in January 2014TRANSCRIPT
![Page 1: Introduction to Go](https://reader033.vdocuments.site/reader033/viewer/2022052412/5594110b1a28abff608b4672/html5/thumbnails/1.jpg)
!
An Introduction to Gogiven January 30, 2014 at CodeFellows
Zack Hubert
![Page 2: Introduction to Go](https://reader033.vdocuments.site/reader033/viewer/2022052412/5594110b1a28abff608b4672/html5/thumbnails/2.jpg)
Hi, I’m Zack
![Page 3: Introduction to Go](https://reader033.vdocuments.site/reader033/viewer/2022052412/5594110b1a28abff608b4672/html5/thumbnails/3.jpg)
I work here…and…
![Page 4: Introduction to Go](https://reader033.vdocuments.site/reader033/viewer/2022052412/5594110b1a28abff608b4672/html5/thumbnails/4.jpg)
I think Go is Awesome
![Page 5: Introduction to Go](https://reader033.vdocuments.site/reader033/viewer/2022052412/5594110b1a28abff608b4672/html5/thumbnails/5.jpg)
I think you’ll like it too
![Page 6: Introduction to Go](https://reader033.vdocuments.site/reader033/viewer/2022052412/5594110b1a28abff608b4672/html5/thumbnails/6.jpg)
My Story with Go
![Page 7: Introduction to Go](https://reader033.vdocuments.site/reader033/viewer/2022052412/5594110b1a28abff608b4672/html5/thumbnails/7.jpg)
The Year was 2012
• It was a NEW PROJECT!
• Make it Real Time
• Use a Javascript MVC
![Page 8: Introduction to Go](https://reader033.vdocuments.site/reader033/viewer/2022052412/5594110b1a28abff608b4672/html5/thumbnails/8.jpg)
Ruby on RailsServer side choice was easy…
![Page 9: Introduction to Go](https://reader033.vdocuments.site/reader033/viewer/2022052412/5594110b1a28abff608b4672/html5/thumbnails/9.jpg)
What about the Client Side?
![Page 10: Introduction to Go](https://reader033.vdocuments.site/reader033/viewer/2022052412/5594110b1a28abff608b4672/html5/thumbnails/10.jpg)
logos believed to be fair use
![Page 11: Introduction to Go](https://reader033.vdocuments.site/reader033/viewer/2022052412/5594110b1a28abff608b4672/html5/thumbnails/11.jpg)
Batman.jsHas been a great choice
![Page 12: Introduction to Go](https://reader033.vdocuments.site/reader033/viewer/2022052412/5594110b1a28abff608b4672/html5/thumbnails/12.jpg)
What kind of product?Resource Scheduling
![Page 13: Introduction to Go](https://reader033.vdocuments.site/reader033/viewer/2022052412/5594110b1a28abff608b4672/html5/thumbnails/13.jpg)
–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](https://reader033.vdocuments.site/reader033/viewer/2022052412/5594110b1a28abff608b4672/html5/thumbnails/14.jpg)
Rails Performance
< 150ms? This could be a problem.
![Page 15: Introduction to Go](https://reader033.vdocuments.site/reader033/viewer/2022052412/5594110b1a28abff608b4672/html5/thumbnails/15.jpg)
SolutionMySQL Upserts
Histogram the Schedule Heavily Precompute Values in Cache
![Page 16: Introduction to Go](https://reader033.vdocuments.site/reader033/viewer/2022052412/5594110b1a28abff608b4672/html5/thumbnails/16.jpg)
It Worked!
![Page 17: Introduction to Go](https://reader033.vdocuments.site/reader033/viewer/2022052412/5594110b1a28abff608b4672/html5/thumbnails/17.jpg)
The Good
• 40ms
• Rails+MySQL
• No NoSQL
• Same stack as other apps
![Page 18: Introduction to Go](https://reader033.vdocuments.site/reader033/viewer/2022052412/5594110b1a28abff608b4672/html5/thumbnails/18.jpg)
The Bad
• Millions of rows of computed values
• Caching is error prone
• Data model polluted with derivative classes
![Page 19: Introduction to Go](https://reader033.vdocuments.site/reader033/viewer/2022052412/5594110b1a28abff608b4672/html5/thumbnails/19.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022052412/5594110b1a28abff608b4672/html5/thumbnails/20.jpg)
Go is Opinionatedfrustration will ensue without knowing the opinions of
the designers
![Page 21: Introduction to Go](https://reader033.vdocuments.site/reader033/viewer/2022052412/5594110b1a28abff608b4672/html5/thumbnails/21.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022052412/5594110b1a28abff608b4672/html5/thumbnails/22.jpg)
Techempower JSON encoding benchmark
http://www.techempower.com/benchmarks bottom is visible :(
![Page 23: Introduction to Go](https://reader033.vdocuments.site/reader033/viewer/2022052412/5594110b1a28abff608b4672/html5/thumbnails/23.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022052412/5594110b1a28abff608b4672/html5/thumbnails/24.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022052412/5594110b1a28abff608b4672/html5/thumbnails/25.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022052412/5594110b1a28abff608b4672/html5/thumbnails/26.jpg)
![Page 27: Introduction to Go](https://reader033.vdocuments.site/reader033/viewer/2022052412/5594110b1a28abff608b4672/html5/thumbnails/27.jpg)
Go turns out to be the best at JSON
…a perfect complement, huzzah :)
![Page 28: Introduction to Go](https://reader033.vdocuments.site/reader033/viewer/2022052412/5594110b1a28abff608b4672/html5/thumbnails/28.jpg)
Why Learn Go?
![Page 29: Introduction to Go](https://reader033.vdocuments.site/reader033/viewer/2022052412/5594110b1a28abff608b4672/html5/thumbnails/29.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022052412/5594110b1a28abff608b4672/html5/thumbnails/30.jpg)
FUN!
![Page 31: Introduction to Go](https://reader033.vdocuments.site/reader033/viewer/2022052412/5594110b1a28abff608b4672/html5/thumbnails/31.jpg)
Overview
• A brief history of Go
• Language design decisions
![Page 32: Introduction to Go](https://reader033.vdocuments.site/reader033/viewer/2022052412/5594110b1a28abff608b4672/html5/thumbnails/32.jpg)
What is Go?Go is a new, general-purpose programming language.
![Page 33: Introduction to Go](https://reader033.vdocuments.site/reader033/viewer/2022052412/5594110b1a28abff608b4672/html5/thumbnails/33.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022052412/5594110b1a28abff608b4672/html5/thumbnails/34.jpg)
The Story of Go
![Page 35: Introduction to Go](https://reader033.vdocuments.site/reader033/viewer/2022052412/5594110b1a28abff608b4672/html5/thumbnails/35.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022052412/5594110b1a28abff608b4672/html5/thumbnails/36.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022052412/5594110b1a28abff608b4672/html5/thumbnails/37.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022052412/5594110b1a28abff608b4672/html5/thumbnails/38.jpg)
The Creation Storylong C++ build, 45 minutes, whiteboarded the language
image still from Google I/O 2012
![Page 39: Introduction to Go](https://reader033.vdocuments.site/reader033/viewer/2022052412/5594110b1a28abff608b4672/html5/thumbnails/39.jpg)
Open Sourced Nov, 2009464 contributors as of January 26, 2014
![Page 40: Introduction to Go](https://reader033.vdocuments.site/reader033/viewer/2022052412/5594110b1a28abff608b4672/html5/thumbnails/40.jpg)
Already Quite Popular(SO vs Github)
![Page 41: Introduction to Go](https://reader033.vdocuments.site/reader033/viewer/2022052412/5594110b1a28abff608b4672/html5/thumbnails/41.jpg)
Problem #1: Development Speed
![Page 42: Introduction to Go](https://reader033.vdocuments.site/reader033/viewer/2022052412/5594110b1a28abff608b4672/html5/thumbnails/42.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022052412/5594110b1a28abff608b4672/html5/thumbnails/43.jpg)
Fast is FUN
![Page 44: Introduction to Go](https://reader033.vdocuments.site/reader033/viewer/2022052412/5594110b1a28abff608b4672/html5/thumbnails/44.jpg)
Fast has its Tradeoffs
“Missing” language features - Generics, Inheritance, etc.
![Page 45: Introduction to Go](https://reader033.vdocuments.site/reader033/viewer/2022052412/5594110b1a28abff608b4672/html5/thumbnails/45.jpg)
and its quirksmanaged imports for instance…but it makes sense
from the creation
![Page 46: Introduction to Go](https://reader033.vdocuments.site/reader033/viewer/2022052412/5594110b1a28abff608b4672/html5/thumbnails/46.jpg)
Problem #2: Make it Modern
![Page 47: Introduction to Go](https://reader033.vdocuments.site/reader033/viewer/2022052412/5594110b1a28abff608b4672/html5/thumbnails/47.jpg)
Age of Languages?
![Page 48: Introduction to Go](https://reader033.vdocuments.site/reader033/viewer/2022052412/5594110b1a28abff608b4672/html5/thumbnails/48.jpg)
C++ 1979
![Page 49: Introduction to Go](https://reader033.vdocuments.site/reader033/viewer/2022052412/5594110b1a28abff608b4672/html5/thumbnails/49.jpg)
Python 1989
![Page 50: Introduction to Go](https://reader033.vdocuments.site/reader033/viewer/2022052412/5594110b1a28abff608b4672/html5/thumbnails/50.jpg)
Java 1990
![Page 51: Introduction to Go](https://reader033.vdocuments.site/reader033/viewer/2022052412/5594110b1a28abff608b4672/html5/thumbnails/51.jpg)
Ruby 1993
![Page 52: Introduction to Go](https://reader033.vdocuments.site/reader033/viewer/2022052412/5594110b1a28abff608b4672/html5/thumbnails/52.jpg)
Go - 2007(14 years after Ruby)
![Page 53: Introduction to Go](https://reader033.vdocuments.site/reader033/viewer/2022052412/5594110b1a28abff608b4672/html5/thumbnails/53.jpg)
Modern Means Multicore
![Page 54: Introduction to Go](https://reader033.vdocuments.site/reader033/viewer/2022052412/5594110b1a28abff608b4672/html5/thumbnails/54.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022052412/5594110b1a28abff608b4672/html5/thumbnails/55.jpg)
Concurrency is HUGE in Go
![Page 56: Introduction to Go](https://reader033.vdocuments.site/reader033/viewer/2022052412/5594110b1a28abff608b4672/html5/thumbnails/56.jpg)
Modern Means Internetit’s kind of a big deal
![Page 57: Introduction to Go](https://reader033.vdocuments.site/reader033/viewer/2022052412/5594110b1a28abff608b4672/html5/thumbnails/57.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022052412/5594110b1a28abff608b4672/html5/thumbnails/58.jpg)
Problem #3: Complexity
![Page 59: Introduction to Go](https://reader033.vdocuments.site/reader033/viewer/2022052412/5594110b1a28abff608b4672/html5/thumbnails/59.jpg)
Webscale.large programs, big teams.
![Page 60: Introduction to Go](https://reader033.vdocuments.site/reader033/viewer/2022052412/5594110b1a28abff608b4672/html5/thumbnails/60.jpg)
Seriously though…
• Designed to be C-like for early career programmers
• Simplified syntax
![Page 61: Introduction to Go](https://reader033.vdocuments.site/reader033/viewer/2022052412/5594110b1a28abff608b4672/html5/thumbnails/61.jpg)
1 keyword for looping
Simple
![Page 62: Introduction to Go](https://reader033.vdocuments.site/reader033/viewer/2022052412/5594110b1a28abff608b4672/html5/thumbnails/62.jpg)
Garbage CollectionSimple, easier with concurrency
![Page 63: Introduction to Go](https://reader033.vdocuments.site/reader033/viewer/2022052412/5594110b1a28abff608b4672/html5/thumbnails/63.jpg)
25 keywords total50 in Java, 48 in C++, ~42 in Ruby
![Page 64: Introduction to Go](https://reader033.vdocuments.site/reader033/viewer/2022052412/5594110b1a28abff608b4672/html5/thumbnails/64.jpg)
No InheritanceComposition is easier to get right, defers design
decisions
![Page 65: Introduction to Go](https://reader033.vdocuments.site/reader033/viewer/2022052412/5594110b1a28abff608b4672/html5/thumbnails/65.jpg)
CSP ConcurrencyMutexes are hard to get right. Channels are easier.
![Page 66: Introduction to Go](https://reader033.vdocuments.site/reader033/viewer/2022052412/5594110b1a28abff608b4672/html5/thumbnails/66.jpg)
So…when Go is confusing ask…
![Page 67: Introduction to Go](https://reader033.vdocuments.site/reader033/viewer/2022052412/5594110b1a28abff608b4672/html5/thumbnails/67.jpg)
Is this because the language is YOUNG?
![Page 68: Introduction to Go](https://reader033.vdocuments.site/reader033/viewer/2022052412/5594110b1a28abff608b4672/html5/thumbnails/68.jpg)
Is this because it’s SIMPLE?
![Page 69: Introduction to Go](https://reader033.vdocuments.site/reader033/viewer/2022052412/5594110b1a28abff608b4672/html5/thumbnails/69.jpg)
Is this because it wants to be FAST?
![Page 70: Introduction to Go](https://reader033.vdocuments.site/reader033/viewer/2022052412/5594110b1a28abff608b4672/html5/thumbnails/70.jpg)
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](https://reader033.vdocuments.site/reader033/viewer/2022052412/5594110b1a28abff608b4672/html5/thumbnails/71.jpg)
Keep on Learnin’
• http://golang.org
• http://gobyexample.org
• http://gophercasts.io
![Page 73: Introduction to Go](https://reader033.vdocuments.site/reader033/viewer/2022052412/5594110b1a28abff608b4672/html5/thumbnails/73.jpg)
Let’s Have Some Questions