introduction to go
DESCRIPTION
Slides from a talk I gave at CodeFellows in January 2014TRANSCRIPT
!
An Introduction to Gogiven January 30, 2014 at CodeFellows
Zack Hubert
Hi, I’m Zack
I work here…and…
I think Go is Awesome
I think you’ll like it too
My Story with Go
The Year was 2012
• It was a NEW PROJECT!
• Make it Real Time
• Use a Javascript MVC
Ruby on RailsServer side choice was easy…
What about the Client Side?
logos believed to be fair use
Batman.jsHas been a great choice
What kind of product?Resource Scheduling
–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?”
Rails Performance
< 150ms? This could be a problem.
SolutionMySQL Upserts
Histogram the Schedule Heavily Precompute Values in Cache
It Worked!
The Good
• 40ms
• Rails+MySQL
• No NoSQL
• Same stack as other apps
The Bad
• Millions of rows of computed values
• Caching is error prone
• Data model polluted with derivative classes
Free Week - 2012
• Looked at Go for an API
• Didn’t understand it
• Frustrated by many things
• Compiler error on unused import…wha!?
Go is Opinionatedfrustration will ensue without knowing the opinions of
the designers
Back to Resources
• 1.5 years later…many users etc.
• The app was getting slower (larger JSON responses)
• Complexity was an increasing burden
Techempower JSON encoding benchmark
http://www.techempower.com/benchmarks bottom is visible :(
Free Week - 2013
• Had been reading up in the intervening year
• Watched every video I could
• and then it made sense…
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)
RUSH Performance
• 100x faster than the heavily cached Ruby option
• 1,000x faster than Ruby without caching
• 1% of the memory footprint
Go turns out to be the best at JSON
…a perfect complement, huzzah :)
Why Learn 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
FUN!
Overview
• A brief history of Go
• Language design decisions
What is Go?Go is a new, general-purpose programming language.
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 :)
The Story of 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
Ken Thompson (seated)designed UNIX, B, Plan 9, Turing award
image cc by-sa 2.0 at en.wikipedia.org
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
The Creation Storylong C++ build, 45 minutes, whiteboarded the language
image still from Google I/O 2012
Open Sourced Nov, 2009464 contributors as of January 26, 2014
Already Quite Popular(SO vs Github)
Problem #1: Development Speed
Development Speed
• “It's a fast statically typed compiled language that feels like a dynamically typed interpreted language.” - golang.org
Fast is FUN
Fast has its Tradeoffs
“Missing” language features - Generics, Inheritance, etc.
and its quirksmanaged imports for instance…but it makes sense
from the creation
Problem #2: Make it Modern
Age of Languages?
C++ 1979
Python 1989
Java 1990
Ruby 1993
Go - 2007(14 years after Ruby)
Modern Means Multicore
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
Concurrency is HUGE in Go
Modern Means Internetit’s kind of a big deal
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
Problem #3: Complexity
Webscale.large programs, big teams.
Seriously though…
• Designed to be C-like for early career programmers
• Simplified syntax
1 keyword for looping
Simple
Garbage CollectionSimple, easier with concurrency
25 keywords total50 in Java, 48 in C++, ~42 in Ruby
No InheritanceComposition is easier to get right, defers design
decisions
CSP ConcurrencyMutexes are hard to get right. Channels are easier.
So…when Go is confusing ask…
Is this because the language is YOUNG?
Is this because it’s SIMPLE?
Is this because it wants to be FAST?
Revised…Original talk proceeded to 1 hour Tour of Go
and then “The Fun Part” (hands-on with Go, using D&D imagery)
Keep on Learnin’
• http://golang.org
• http://gobyexample.org
• http://gophercasts.io
Thank You!@zhubert, http://www.zhubert.com
Let’s Have Some Questions