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
79
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
42
Separating Your Application from Rails - Brian Hughes
lvrug
0
94
SWIG and Ruby - David Grayson
lvrug
0
51
Practical Object-Oriented Design in Ruby - Charles Jackson
lvrug
3
110
Varnish+Redis - Russ Smith
lvrug
1
80
Lambdas and Pops - Jan Hettich
lvrug
0
49
Making Good Use of Fonts - Russ Smith
lvrug
1
62
Writing Files - Ryan Mulligan
lvrug
0
39
Featured
See All Featured
Git: the NoSQL Database
bkeepers
PRO
427
64k
Bootstrapping a Software Product
garrettdimon
PRO
305
110k
Visualization
eitanlees
146
15k
Build The Right Thing And Hit Your Dates
maggiecrowley
33
2.5k
Fontdeck: Realign not Redesign
paulrobertlloyd
82
5.3k
Code Review Best Practice
trishagee
65
17k
Building Better People: How to give real-time feedback that sticks.
wjessup
366
19k
GitHub's CSS Performance
jonrohan
1030
460k
Thoughts on Productivity
jonyablonski
68
4.4k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
38
1.9k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
656
59k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
3
240
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