Share
Embed
Dysfunctional Ruby
A short 30min talk for Malaga Scala Meetup about caticorns and why rubyists deserve better.
http://www.meetup.com/es/Malaga-Scala/events/223598765
Nando Sola
July 15, 2015
Transcript
19 slides
-
1. The trouble with nil 2. The inheritance crisis 3.
Bad romance overflow 4. Please don’t mutate my feelings 5. Share the love, not the state 6. True love scales -
1. The trouble with nil nil is a leaked abstraction
Don’t take nil for granted -
Procedural code gets information then makes decisions. Object-oriented code tells
objects to do things. — Alec Sharp, “Smalltak by Example” http://sdmeta.gforge.inria.fr/FreeBooks/ByExample/SmalltalkByExampleNewRelease.pdf https://pragprog.com/articles/tell-dont-ask -
2. The inheritance crisis Extending core classes in Ruby is
a bad idea Integers are “immediates”, ie. architecture-dependent The rest are implemented in C (MRI/YARV), for efficiency http://words.steveklabnik.com/beware-subclassing-ruby-core-classes -
3. Bad romance overflow These implementations will fail for large
values of n SystemStackError: stack level too deep why? -
Ruby (YARV) has TCO since version 1.9 JRuby depends on
the JVM optimizations Rubinius won’t implement TCO http://chris.mowforth.com/posts/2011/avoiding-stack-overflow-in-ruby-with-trampolines/ http://blog.vmoroz.com/posts/2015-04-18-generic-recursion-in-ruby-with-trampolines-and-thunks.html Solution: be agnostic (and lazy) -
4. Please don’t mutate my feelings In Ruby, only Fixnum
and Symbol are immutable Using Struct and OpenStruct is not OK #freeze and #dup are not your friends -
http://ruby-doc.org/core-2.0.0/Enumerator/Lazy.html https://github.com/hamstergem/hamster https://github.com/tcrayford/Values Use the std and core libraries Use
gems that provide immutability Namespace pollution Expect a good deal of metaprogramming under the hood Compatibility with the other “good gems” -
5. Share the love, not the state Ruby (YARV) just
provides Thread and Fiber primitives Their underlying implementations vary from GIL to 1:1 models Rubinius and JRuby: real multithreading Rubinius provides an additional actor model http://merbist.com/2011/02/22/concurrency-in-ruby-explained/ http://www.jstorimer.com/products/working-with-ruby-threads http://rubini.us/doc/en/systems/concurrency/ -
Use an implementation-agnostic gem for concurrency Advanced thread sync mechanisms
Futures/Promises Channels Actors I/O reactor If possible, use Rubinius or JRuby Real threads Look for servers/clients using these https://github.com/celluloid/celluloid https://github.com/ruby-concurrency/concurrent-ruby https://github.com/celluloid/celluloid-io -
6. True love scales Ruby has a remote object framework
in its stdlib (dRuby) Enables remote method calling Peer to peer Each remote method invocation is handled synchronously by a new server thread Not truly concurrent (Mutex needed) A distributed, immutable “tuplespace" is shared among all objects (Rinda) https://news.ycombinator.com/item?id=4696027 http://ruby-doc.org/docs/Distributed%20Ruby%20(drb%20and%20Rinda)/DistributedRuby.pdf -
JRuby Mikka Java-flavored Akka Rubinius rubinius-actor Remoting is “bleeding-edge” Agnostic:
DCell (distributed objects for Ruby) External systems: Redis, RabbitMQ, … https://github.com/iconara/mikka https://www.ruby-forum.com/topic/5957087 http://doc.akka.io/docs/akka/snapshot/java/untyped-actors.html -
Use a functional language Scala, Clojure and Erlang have (most
of) all of these features already baked-in No need for extra gems No need to stretch the boundaries of the language No need to hide anymore -
Thanks! @mr_solo github.com/nandosola http://www.planetminecraft.com/skin/ruby--steven-universe/ All images are memes or can
be found CC’d in Flicker. Cover art by