I’ve been a front-end developer for about two years now, and I’m attempting to break into the server side of things. Ideally I’d like to work for a startup social network on the back-end side so I want to try and be as marketable as possible.
In my quest to learn a new scripting language I’ve dug myself into the PHP vs Ruby hole. What are the main advantages and disadvantages of the two? I would really appreciate words from experience with the two, but will settle for any experience.
Cheers.
1
I’ve been a PHP developer for about five years, and in the last year I started looking into the Ruby (on Rails) world. I’m never going to go back. Here’s why.
Inconsistency
I was displeased with PHP mostly because of its inconsistency: PHP was originally intended as a tool for amateurs, and it couldn’t cope with the exponential growth it has seen over the years. In PHP you have random function names, random parameter order, random return values, random error handling and lots of other randomness.
Object-orientation
I was looking for a language that was truly object-oriented (i.e. a language where everything’s an object) and that had a beautiful syntax. Ruby seemed to be the most appropriate option. Sure, it has its problems like every other technology (I don’t really like this monkey-patching stuff, and Rails in particular seems to be quite slow compared to other frameworks).
Syntax
This is a subjective matter, but I’ll put it anyway. I wanted my code to be expressive, concise, and beautiful. To me, PHP code has always been an ugly mess.
Here’s an example: suppose that you have an array of objects and that you want to call a method on those objects and sum the returned values. Here’s the PHP code for it:
array_sum(array_map(function($object) {
$object->foo();
}, $objects));
Not so bad, is it? Here’s the same with Ruby:
objects.collect(&:foo).sum
Now, this might seem a small improvement, but when you’re writing lots of code I can assure you that it does make a difference.
Community
With the birth of modern web frameworks like Symfony (God bless the authors!) and Laravel this situation has slightly improved, but this point is still partially true.
The PHP community is terrible: most of them have no interest in improving the tools they’re working with, and just care about getting stuff done as quickly as possible with as little effort as possible. The amount of wrong/outdated information about PHP out there is impressive.
That’s why I’ve decided to maintain the Italian translation of PHP: The Right Way, even though I don’t use PHP anymore. I know that PHP isn’t going anywhere, at least for the next decade, and I’d like to improve all the terrible spaghetti code that I’ve read over the years.
What is PHP good for?
As I’ve said, PHP is a language designed for amateurs. All web hostings out there support it, and you can just upload your script through an FTP client and let it run. This works well for small applications that don’t require a lot of design or maintenance.
All the other technologies, on the other hand, require a bit of setup and tweaking to work well, but it pays off in the long run.
Further reading
There are many rants out there about PHP. The best are:
- PHP: a fractal of bad design
- The PHP Singularity
2