From PHP to Ruby on Rails: what tripped me up
I spent years writing PHP. A lot of it with Symfony. Then I changed jobs, and the main app here is Ruby on Rails. So for the last couple of months I have been relearning how to build web apps.
It is not that hard to be productive in Rails. That is kind of the problem. You become productive before you actually understand what is happening, and that gap bothered me for a while.
Here is what tripped me up.
Blocks and implicit returns
Ruby blocks took me longer than I want to admit. In PHP I think in functions and explicit returns. In Ruby you pass blocks around everywhere, with do ... end or curly braces, and methods like each, map, select expect them.
And the last expression in a method is the return value. No return keyword needed. The first time I read someone else’s code and there was no return anywhere, I genuinely wondered how the method gave back a value. Now I like it, but at first it felt like the code was hiding something from me.
ActiveRecord and the “magic”
ActiveRecord is the part that impressed me and worried me at the same time.
You define a model, and suddenly it knows how to talk to the database, knows the column names, knows the associations. User.where(active: true).order(:name) just works. You can write user.posts and it figures out the join.
Coming from a world where I wrote more of that by hand, it felt like too much was happening behind a curtain. I did not trust it. I kept wanting to see the SQL. (You can, with .to_sql, which helped me calm down.)
Convention over configuration
Symfony made me configure a lot. YAML files, annotations, wiring things together. Rails has way less of that. If you name things the right way, it just connects them. The table is users, the model is User, done.
The upside is obvious: less boilerplate. The downside is that when you do not know the conventions yet, things work by “magic” and you cannot see why. So I spent time learning the conventions, because once you know them the magic turns back into rules.
The testing culture
This one surprised me the most. The testing culture here is strong. People write tests as a normal part of the work, not as a chore you do at the end if there is time. RSpec is everywhere, and the way it reads is closer to plain English than what I was used to.
I was not in the habit of testing that much before. Here it is just expected, and honestly it has made me slower in a good way. I think more before I write.
Mixed feelings
I will be honest, I have mixed feelings. I love how fast you can move, and I love how readable Ruby is. But I distrusted all the magic at the start, and a little of that distrust is still there. The difference now is that I have looked behind enough curtains to know there is no actual magic, just conventions I had not learned yet.
Still learning. But I get it more than I did two months ago.