PHP vs Ruby – Let’s All Just Get Along
Quite often you see developers who have a lot of experience in one language try to play with another, then make a rather quick comparison between the two. This comparison is usually quite worthless, but the clickbait titles get them a lot of traffic.
Instead of doing that, I thought it would be interesting to have a slightly more fair comparison, from the perspective of someone who really enjoys writing both PHP and Ruby, and has done so for years. The aim here is not to find out which is “better”, but to point out a few key things I like about Ruby and its ecosystem.
Different languages are often compared to find out which is better, when the differences that make them up are more ideological. Sometimes one thing seems better to one group of people, when that very same thing makes the language a nightmare for other developers.
With this in mind, before I get into the “bits of Ruby I like in comparison” I think explaining a few of these conceptual differences will be important.
Method, Variable, Property?
PHP offers different syntax to access properties, methods or variables. Ruby does not.
$this->turtle # Instance Property $this->bike() # Method $apple # Variable
@turtle # Instance Property turtle # "Instance Property" using attr_reader: :turtle bike # Method apple # Variable
Pedants will point out here that
attr_reader :turtle will define a method dynamically, which is used as a getter for
bike the same thing. A PHP developer looking at usage of
turtle with no method or variable name explicitly defined will be incredibly confused about where it’s coming from.
Continue reading %PHP vs Ruby – Let’s All Just Get Along%