Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
The Hamster Gem - Ryan Mulligan
Search
Las Vegas Ruby Group
July 16, 2014
1
78
The Hamster Gem - Ryan Mulligan
Las Vegas Ruby Group
July 16, 2014
Tweet
Share
More Decks by Las Vegas Ruby Group
See All by Las Vegas Ruby Group
Ruby ISO Standard - David Grayson
lvrug
0
100
Windows Automation - Howard Feldman
lvrug
0
40
Separating Your Application from Rails - Brian Hughes
lvrug
0
91
SWIG and Ruby - David Grayson
lvrug
0
49
Practical Object-Oriented Design in Ruby - Charles Jackson
lvrug
3
100
Varnish+Redis - Russ Smith
lvrug
1
78
Lambdas and Pops - Jan Hettich
lvrug
0
46
Making Good Use of Fonts - Russ Smith
lvrug
1
60
Writing Files - Ryan Mulligan
lvrug
0
37
Featured
See All Featured
Rails Girls Zürich Keynote
gr2m
94
13k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
44
9.3k
Side Projects
sachag
452
42k
Automating Front-end Workflow
addyosmani
1366
200k
Typedesign – Prime Four
hannesfritz
40
2.4k
Docker and Python
trallard
41
3.1k
A designer walks into a library…
pauljervisheath
204
24k
Thoughts on Productivity
jonyablonski
67
4.4k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
191
16k
Six Lessons from altMBA
skipperchong
27
3.5k
A Tale of Four Properties
chriscoyier
157
23k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
44
6.9k
Transcript
“Efficient, immutable, and thread-safe collection classes for Ruby.” the hamster
gem
“Efficient, immutable, and thread-safe collection classes for Ruby.”
“Efficient, immutable, and thread-safe collection classes for Ruby.”
containers for objects
tuple (1, 2, 3)
set {1, 2, 3}
hash {:name => "James", :gender => :male}
vector (like array) [1, 2, 3, 4, 5]
stack User:Boivie http://en.wikipedia.org/wiki/Stack_(abstract_data_type)#mediaviewer/File:Data_stack.svg
queue User:Vegpuff on wikipedia http://en.wikipedia.org/wiki/Queue_(abstract_data_type)#mediaviewer/File:Data_Queue.svg
(linked) list
“Efficient, immutable, and thread-safe collection classes for Ruby.”
immutability
require "hamster" person = Hamster.hash(:name => "Simon", :gender => :male)
person[:name] # => "Simon" friend = person.put(:name, "James") # => {:name => "James", :gender => :male} male = person.delete(:name) # => {:gender => :male} person # => {:name => "Simon", :gender => :male} male.key?(:name) # => false
the sales pitch
immutability is a good thing™
Mutable stateful objects are the new spaghetti code: - hard
to understand, test, reason about - Concurrency disaster Rich Hickey - Clojure “
Immutable objects are simple. Classes should be immutable unless there’s
a very good reason to make them mutable. If a class cannot be made immutable, limit its mutability as much as possible. Josh Bloch, in Effective Java “
you are using immutable data
git, bitcoin blockchain, :ruby
benefits readability concurrency (thread-safety)
“Efficient, immutable, and thread-safe collection classes for Ruby.”
person = Hamster.hash( :name => "Simon", :gender => :male, #...
1000 other key-value pairs ) person[:name] # => "Simon" friend = person.put(:name, "James") # => {:name => "James", :gender => :male, #...} Does friend have to copy everything from person?
NO!
“Efficient, immutable, and thread-safe collection classes for Ruby.” NO!
“Persistent, immutable, and thread-safe collection classes for Ruby.” NO!
zs = xs + ys
None
adding e
“Efficient, immutable, and thread-safe collection classes for Ruby.”
immutability => thread safety
warning: references immutable but contents might be mutable
require 'hamster' v = "A" h = Hamster.hash(:k=>v) #=>{:k =>
"A"} v[0] = "B" h #=> {:k => "B"}
“Efficient, immutable, and thread-safe collection classes for Ruby.”
references https://deveo.com/blog/2013/03/22/immutability-in-ruby-part-1/ https://deveo.com/blog/2013/03/28/immutability-in-ruby-part-2/ http://clojure.org/state http://en.wikipedia.org/wiki/Persistent_data_structure https://github.com/hamstergem/hamster slides https://github.com/ryantm/lvrug_hamster