Why PHP is better than Ruby

PHP is better than ruby. There, I said it. In this article I'm going to show you why, and probably upset some twenty-something, flip-flop clad, mac-using hippie fanboys in the process.

In Ruby, everything is an object... even literals!

This is just nuts. I don't know how ruby developers can call themselves real programmers. In PHP we don't believe in a standard interface. We celebrate our diversity. Is it hayatack, needle or needle, haystack? Should we call a method on an object or pass it into a function? Should we do both and code in various different styles just to make life interesting?

Compared to the daily adventure of figuring out how PHP works, Ruby is boring. Take string processing functions. To do a simple string-replace in Ruby, you have to call a function on your string literal, not pass it into a string processing function. What sort of object-oriented crack was Matz smoking? This takes all the enjoyment out of programming!

{%highlight php%} <?php //replace foo with bar the sensible, PHP way str_replace('foo', 'bar', 'I eat food and play football')

I eat bard and play bartball


{%highlight ruby%}

What ragamuffin thought up this object-oriented codswallop?

"I eat food and play football".gsub('foo', 'bar') {%endhighlight%}

Also, I get the feeling that the developers of ruby were being deliberately facetious when they thought up the language. Fine, let's go as far as agreeing that everything is an object. But even classes? "Classes are objects of class Class"? Surely someones having a laugh at those poor ruby developers expense.

Ruby's syntax is impossible to understand!

Ruby has some crazy labrynthian syntax quirks that are impossible to understand for normal human beings. Take a look at this for example:

{%highlight ruby%} class Address attr_accessor :name, :line1, :line2, :county, :postcode, :country

def Address.valid_postcode?(string)
    #true for valid postcode, false otherwise

def initialize(data)
    if data[:postcode]
        raise "Invalid postcode" unless Address.valid_postcode?(data[:postcode])

end {%endhighlight%}

This code is incomprehensible... First of all, there are no curly braces anywhere. Curly braces make me feel safe and loved, and I don't see any curly braces here. Also, I lose all sense of balance if I don't have paranthesis. Although too many parenthesis is a bad thing (don't get me started on how much I hate Lisp), surely we need them for conditionals? Function parameters? Can no one else see the madness here?!

PHP allows me to practice my typing skills, ruby doesn't

As a touch-typing enthusiast, I like to practice typing. The problem with ruby is that it allows me to do the same things that I can do in PHP, but with much less typing. Take a look at this example of a simple class with getters and setters in PHP, and then in Ruby:

{%highlight php%} <?php

class Address { private $name; private $line1; private $line2; private $county; private $postcode; private $country;

public function getName() {
    return $this->name;

public function getLine1() {
    return $this->line1;

public function getLine2() {
    return $this->line1;

public function getCounty() {
    return $this->county;

public function getPostcode() {
    return $this->postcode;

public function getCountry() {
    return $this->country;

public function setName($newName) {
    $this->name = $newName;

public function setLine1($newLine1) {
    $this->line1 = $newLine1;

public function setLine2($newLine2) {
    $this->line2 = $newLine2;

public function setCounty($newCounty) {
    $this->county = $newCounty;

public function setPostcode($newPostcode) {
    $this->postcode = $newPostcode;

public function setCountry($newCountry) {
    $this->country = $newCountry;

} {%endhighlight%}

And now look at the same thing, with the same access in ruby...

{%highlight ruby%} class Address attr_accessor :name, :line1, :line2, :county, :postcode, :country end {%endhighlight%}

That is too short to be of any use to anyone. If I could create classes with public getters/setters that easily in my day-job, my fingers would atrophe and I'd get no exercise at all. I want my keyboard smoking after typing out a class definition, and a paltry three lines of ruby fails to satisfy.

Also, bugs caused by typos are the highlight of my day, and prefer a syntax that allows me to write as many of those as I can. Ignore that blasphemous ruby code with it's concise, expressive syntax. Focus on those warm, safe curly braces. There, that's better...

Ruby doesn't let you create arbitrary public members on objects!

One killer feature of PHP is the ability to set arbitrary public attributes on objects by default. Take a look at this PHP code:

{%highlight php%} <?php

class Address { //as above.. }

$address = new Address(); $address->xCoordinate = 54; $address->yCoordinate = 73; {%endhighlight%}

So you can put arbitrary data on an object wherever you like in your code! Furthermore, you don't have to declare it, document it or refer to it in any way. Feel free to write code in other parts of your system that rely on these public values being set. This is great for job security, as no one else will want or be able to understand how your code works.

Ruby let's you redefine classes, whenever the hell you want, including the standard library!

In ruby, you can do this:

{%highlight ruby%}

the class for integers in ruby

class FixNum def +(adder) self - adder end end

that's correct biyotches, I just turned addition into subtraction


There has got to be something wrong with a language that allows you to subvert the rules of basic arithmetic!

On a more serious note, developers are inherently stupid. And evil. Given the opportunity, they will check pure horseshit into version control and simply cannot be held accountable for their actions. Having a feature that allows you to re-write language fundamentals at will is just asking for trouble from all the stupid, malicious developers in your organization.

In the most extreme cases, ruby developers in their natural habitat have been reported to create entire sub-dialects of the language, reshaping the language for their given domain. Whatever you do, don't let this sort of heretical madness into your organization.


I've made my case, ruby is impossible to understand and gives developers seemingly arbitrary control over the language. I thoroughly recommend you reconsider before attempting to learn ruby. It's like a zombie infection, before you know it you'll be using git for version control, working from home in textmate and bizarre functional programming paradigms will start making their way into your PHP.

You've been warned.

Update: Thanks for all the comments guys! Some of them quite funny, others informative and others just downright confused. I'm going to wrap things up with this posts comments now as the conversations dragging on a little. In the meantime, have a look at the traffic stats for this post.

blog comments powered by Disqus