josefrichter

josefrichter

I was looking at some news about Ruby 3 (see Ruby 3.0.0 Released | Ruby) and came also across this GenServer implementation which I thought I’d share here:

What do you folks think about Ruby 3? What kind of applications does it open in Ruby world that were previously not feasible? How does it compare to Elixir, what might be the implications, good or bad.

Just to be clear, I am curious about your opinions, not in some pointless Ruby vs Elixir flamewar. I love both Elixir and Ruby and I am pretty sure many people in this forum feel the same.

Showing Posts 1 to 9

subbu

subbu

I haven’t read Ruby 3 feature list yet, but IMO, GenServer gets its power from OTP/BEAM and its ability to run long running processes. You can store arbitrary data in the process and use it however you want. I am not sure actor model is powerful without a VM. What do others think?

al2o3cr

al2o3cr

Some quick observations:

  • mixing mutable objects with an idiom intended for immutable data feels weird; an instance of Stack is threaded through every call, but functions like Stack#push mutate the data inside it, leading to code with hidden connections:
    case msg
    in [:push, value]
      push(value) # <= mutates self
      [:noreply, self]
    end
  • corollary: If a handler accidentally returns a reference to state to a caller, now you’ve got unsynchronized access to a shared mutable data structure :skull_and_crossbones:

  • the handle_cast / handle_call idiom is very dependent on pattern-matching in function heads; while it’s not semantically different to have a single body with a giant case, it doesn’t seem as readable to me.

  • overall, I’m not sure if trying to exactly reproduce the gen_server plumbing is the right approach. I’ll be very interested to see what people build with more Rubyish idioms.

dimitarvp

dimitarvp

As others pointed out, the runtime is much more important than the actor model (the model is not some magic by itself). After all, we have actor systems implemented in many languages and I’ve heard people walk away from Akka and Orleans disappointed due to lack of part of the guarantees that the BEAM VM has (although let’s be objective here, most users of these libraries are satisfied).

If people use some sort of a linter / static code checker in combination with Ruby’s actor support that ensures only immutable data are passed around (I believe you can achieve this in Ruby with the .freeze method), then it could work. But then you also need a reliable messaging inbox implementation for all actors.

Me too.

egze

egze

Wondering if the start_link even makes sense in Ruby? Does it really link anything?

lucaong

lucaong

I think it’s a great feature that has the potential to bring a solid concurrency pattern to Ruby. I think that it is quite amazing that Ruby adopted the actor model: this has the potential to make Ruby even better than it already was.

Is this making Ruby preferable to Elixir/Erlang for concurrency? Most likely not, because of the issues with mutability mentioned above, and the lack of a VM designed from the beginning for safe concurrency. But I believe that’s not the point: this feature makes Ruby better, and applicable to more problems than it used to be.

I think about this as beneficial “cross-pollination” between languages, not as a competition.

As an engineer that loves both Ruby and Elixir, this feature makes me happy, as it expands the creative space of my favorite tools. If I am designing specifically for concurrency, I will still reach for Elixir. But in a project that fits Ruby better, this makes it possible to introduce concurrency where needed, using a pattern I like.

As for the GenServer implementation, I look at it more as an example to understand how Ractors work, than as a piece of code I would introduce in a real app. It wouldn’t make real sense to port exactly OTP GenServers to Ractors, as the underlying system is different. In Ruby, I would use the actor model idiomatically, without trying to mimic OTP too closely.

kokolegorille

kokolegorille

It seems they also have ractor supervisors, so it might make sense.

dimitarvp

dimitarvp

I have seen several Rust libs (frameworks?) that employ the actor model and they all go subtly different about it compared to the OTP, which is good and we might need the innovation. It’s nice that not everyone is trying to yet again prove the impossible thesis that shared state with naked OS threads will work for sure this time. :003:

ityonemo

ityonemo

Yeah, I’d say gen_server interface is the worst. Ok. I’m exaggerating (I also appreciate that there is a reason why gen server looks like it does), but I really take Dave thomas famous “dogs breakfast” criticism to heart. Only reason I don’t use a package to organize it is because I think it’s bad form to add an unnecessary abstraction layer into the mental model for a commonly accepted pattern… One of these days I’ll do “isaacs best practices with gen_server” video, but I’m baffled by why someone working with ruby would ever want to repeat what exists verbatim, except that maybe they are worried about losing relevance to elixir.

gregvaughn

gregvaughn

It’s funny how things come together. I don’t know the Ruby 3 feature list, but I learned of an actor framework in Ruby that was strongly influenced by OTP (GitHub - celluloid/celluloid: Actor-based concurrent object framework for Ruby · GitHub) about the same time I heard of Elixir in 2013, and even then, I was more interested in Elixir because it was running on BEAM and could take advantage of its guarantees.

— All posts loaded —

Where Next? Top

Trending in Discussions Top

budgie
A little off-topic, but I feel like people here have a good head on their shoulders. I used to be quite good at making software. Was luc...
New
axelson
Hi there! :wave: @frigidcode and I (but mostly him) have been running an Elixir Book club, we’re almost done with Designing Elixir Syste...
New
juhalehtonen
There has been a thread to discuss the Stack Overflow Developer Survey on this forum every year since 2018, so here’s yet another one for...
New
achempion
I’ve been using Emacs as my main code editor for more than a two years. It’s a custom build version although I’ve tried doom emacs and sp...
New
budgie
I love Elixir. It’s one of 2 programming languages I’ve ever fallen in love with. But I don’t use it anymore. Serverless was the promis...
New
jtormey
Lately I’ve been thinking about how to organize components as a LiveView application grows. One of the pain points I’ve found (for myself...
New
Null-logic-0
What IDE or editor are you using for Elixir development? Personally, I use Zed, and I really like it, but sometimes I wish there were a ...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
KristerV
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
mudasobwa
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
ausimian
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
OndrejValenta
(I just needed to vent somewhere and LinkedIn is full of hope, or hype, I’m not sure which exactly) AI dream has many faces, but general...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews