This is an old article I wrote in 2019 as I was getting started with Ruby. I feel very differently about everything mentionned here now!
After years of mainly writing PHP, I started working with Ruby and Rails. I always loved the ruby philosophy and especially DHH, but I never got to really get into it. I’m also very aware of what Rails brought to web frameworks of any languages. Many of the feature I love in PHP are heavily inspired by Rails.
That being said, I found many things fairly surprising.
Everything described here is my sentiments, it can be wrong because I’m very new in Ruby while I’m very confident in my PHP skills and community awareness. I’m using RVM and Bundler v2.
Learning a new language is not about the syntax but about understanding a new paradigm, acknowledging how people do things and apprehending the state of the community: tooling, dependencies, deployments and “best practices”.
Dependencies are installed globally
With Ruby, you’ll most likely install your dependencies with Bundler via the command bundle install
.
All dependencies are installed in a hidden folder somehere on your laptop (it depends on your configuration and how you installed Ruby).
So if you have a project with requiring a dependency v1.3.4 and another requiring v1.2.8, you'll find both version in the folder. So, if multiple project use the same dependency, it's installed only once.
Coming from PHP, I expected a vendor folder to be created in my projects holding all my dependencies.
Bundler has a way to install gem in a local folder with the —path
option, but it doesn’t seem very popular.
Rails is less opinionated than you think
Coming from Laravel, I’m used to fully featured framework that comes with ORM, user management, model serialisation and such.
After I installed a fresh new version of Rails 6, I looked for the User model and the authentication flow. It didn’t exist, by default, Rails has no user management. Then, you start looking for a gem, but since you’re new to Rails: what should you choose?!
The great news, is that Rails has something called Application Templates to help you preconfigure a Rails with the gems you like, some default routes or extra commands.
By default, Rails comes with the famous ActiveRecord gem. I discovered that there are ways to replace it for Mongoid or Sequel for instance.
The issue I have with this, is that if you’re building a package (a gem) you can’t assume what the user have, and you kinda feel like you should maintain compatibility with alternatives. You can’t assume anything about the User model the app is using, you don’t have an easy way to serialize models, and so on.
I love how Laravel come with more by default.
You need a server to Rails (like Puma or Unicorn)
One thing I really liked about PHP is that it’s stateless. For every request, the whole thing is booted, nothing (unless you do it) is shared between request. It might not be the best for performances but that makes it very easy to reason about.
To run Rails, you need Puma or Unicorn running. I won’t get into details about it, but I think it’s one more steps that makes Rails a little bit harder to get started with.
With that said, I'm loving Ruby right now. The language, the community and the mindset is everything I like. I'm glad I had the opportunity to work with Rails at Algolia.