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
77
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
99
Windows Automation - Howard Feldman
lvrug
0
38
Separating Your Application from Rails - Brian Hughes
lvrug
0
89
SWIG and Ruby - David Grayson
lvrug
0
44
Practical Object-Oriented Design in Ruby - Charles Jackson
lvrug
3
100
Varnish+Redis - Russ Smith
lvrug
1
76
Lambdas and Pops - Jan Hettich
lvrug
0
43
Making Good Use of Fonts - Russ Smith
lvrug
1
58
Writing Files - Ryan Mulligan
lvrug
0
36
Featured
See All Featured
Six Lessons from altMBA
skipperchong
27
3.5k
How GitHub (no longer) Works
holman
310
140k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
44
6.8k
Building Flexible Design Systems
yeseniaperezcruz
327
38k
No one is an island. Learnings from fostering a developers community.
thoeni
19
3k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
28
2k
BBQ
matthewcrist
85
9.3k
Music & Morning Musume
bryan
46
6.2k
Building Applications with DynamoDB
mza
90
6.1k
Teambox: Starting and Learning
jrom
133
8.8k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
109
49k
Become a Pro
speakerdeck
PRO
25
5k
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