On Wed, Oct 26, 2011 at 10:40 PM, Josh Cheek <josh.cheek / gmail.com> wrote:
> As an aside, if I had a real need for parallelism, I'd probably select a
> language better suited to it (e.g. Clojure). Maybe if the community offered
> some good resources about how to safely develop parallel code I'd be more
> comfortable using Ruby, but right now, I prefer the safety of the GIL.

It's not an unreasonable decision to consider Clojure, but the rules
it forces you to follow can also be followed voluntarily in Ruby.

Parallelism is possible (and not terribly difficult) in Ruby, but it's
also somewhat easy to shoot yourself in the foot if you don't know
what you're doing. Clojure, on the other hand, makes it much harder to
shoot yourself in the foot...but it's also not Ruby, and you need to
dig Lisp to enjoy using it.

I'd love to see more techniques from Clojure applied to Ruby, such as
in the Hamster library (a port of Clojure's persistent data structures
to Ruby). I often state my "four rules of safe concurrency":

Rule #1: Don't do it if you can avoid it.
Rule #2: If you must do it, don't share data across workers/threads/processes.
Rule #3: If you must share data, don't share mutable data.
Rule #4: If you must share mutable data, synchronize access to it.

If you follow these rules, you'll live a happy and fruitfully parallel life.

- Charlie