Ruby is a Playground, PHP is a Factory 30

Posted by Kurt Schrader Wed, 21 May 2008 20:17:00 GMT

While reading yet another article on why PHP Sucks (today's witty twist, "but It Doesn't Matter") I realized yet another reason that I'm glad to be programming in Ruby.

Ruby, to me, is like a big open playground, while languages like PHP remind me of big industrial factories. I don't think that any of us would argue that industrial factories are more efficient for most things, but they also suck the creativity and life out of the people working in them.

For instance, why would you ever want to write code like this:

class DescribeNewBowlingGame extends PHPSpec_Context
{
    private $_bowling = null;
    public function before()
    {
        $this->_bowling = new Bowling;
    }

    public function itShouldScore0ForGutterGame()
    {
        for ($i=1; $i<=20; $i++) {
            $this->_bowling->hit(0); // someone is really bad at bowling!
        }       $this->spec($this->_bowling->score)->should->equal(0);
    }

}

when instead you can write this:

describe Bowling do
  before(:each) do
    @bowling = Bowling.new
  end

  it "should score 0 for gutter game" do
    20.times { @bowling.hit(0) }
    @bowling.score.should == 0
  end
end

You wouldn't. The first case is, at best, a bastard representation of the second case.

Of course, being out on the playground means that people get hit in the face with a ball once in a while, and everything isn't as neatly laid out for you as it is in a factory, but you also have the option to be creative, and not just do things like everyone else does.

And, sure, the playground is far more full of assholes than the factory, but these assholes are also more creative and entertaining to work with than people who just put widgets in place in a factory.

Plus the playground has that weird kid in the corner who's doing something totally crazy, but that just might be a genius, and if you get enough of these kids together, you're going to produce something that's much cooler and more creative than anything that gets built in a factory.

So you can talk all you want about big boring websites being written in PHP (or Java, etc).

As for me, I'll keep working in a language that encourages people to be creative.

Comments

Leave a comment

  1. Avatar
    x about 1 hour later:

    This is a pretty bad illustration of Ruby since the two listings are very close in spirit and almost in syntax as well. There are plenty of examples where Ruby will shine over PHP, but this is definitely not one of them.

  2. Avatar
    Kurt Schrader about 1 hour later:

    X: My point wasn't to show the full gamut of differences between Ruby and PHP, as there are plenty of places that do that.

    That being said, the Ruby example does have a DSL for clean syntax and a good use of iterators, both things that you could never do in PHP.

    Most importantly though, it's just a much, much cleaner way to represent the same thing.

  3. Avatar
    kamilpawlik.pl about 2 hours later:

    The worst comparision i've seen. Believe me, no only You glad of being Ruby programmer, probably mosd PHP programers are more glad than you that you are not a php programmer Exactly that kind of persons are making PHP what it is. Just take you time in coding but no in writings stupid comparisions about thinhs you have no idea.

    Regards, frustrated ruby programmer.

  4. Avatar
    Steffen Hiller about 3 hours later:

    I actually find this a good post and comparison.

    kamilpawlik.pl, how would you write that example in php?

    Regards, mostly happy ruby programmer.

  5. Avatar
    Steffen Hiller about 3 hours later:

    Haha, that php example is actually the "officially" example from the http://www.phpspec.org/ front page, kamilpawlik.pl. ;-) That makes it even more interesting to see your (better?) php code?

  6. Avatar
    kamilpawlik.pl about 16 hours later:

    @Steffen, don't you think that nobody's matter about many comparisions posten on the internet? if someone changing language because of post like this is non experienced or stupid. In my opinion enough post was writen about comparising php to ruby, or python. Nevermind, just forget that i wrote comments here.

  7. Avatar
    JustAGeek about 18 hours later:

    This is a somewhat inaccurate comparison in that it you aren't really comparing with PHP but with a PHP implementation of a unit test-framework. While I agree that this specific implementation is kinda ugly in comparison to how it's in Ruby, this doesn't have anything to do with the fact that it's PHP, just that it's implemented in PHP but you do something more elegant and similar to the Ruby solution in PHP, too.

    On the language level you're really only comparing the different methods of iterating and to jump to a conclusion such as yours, just because of that is kinda far-fetched.

    The whole metaphore of yours is really broken anyways.

  8. Avatar
    forsooth about 19 hours later:

    Don't know much about either language, but I prefer the first (PHP) example for "code cleanliness," etc. I'll bet that, in the end, it would be easier to decipher.

  9. Avatar
    Adam about 19 hours later:

    I actually think PHP is more like a playground...a disorganized mess and full of chaos unless some order is brought in (by someone more experienced) to organize it. Ruby is more like a hippie love fest...everyone is idealistic, happy, and totally convinced that their new path of righteousness can bring about peace and joy to all. They're also frustrated by everyone who just doesn't get it.

    For better or for worse, there are many more developers out there willing to hang out at the playground then embrace the new zen culture...it just doesn't fit their style.

  10. Avatar
    Ivan about 19 hours later:

    An apple allows me to be more creative than an orange!

  11. Avatar
    Ivan about 19 hours later:

    Actually after reviewing the "code" samples, I feel pretty comfortable saying I'm glad you're coding Ruby too, and staying away from any applications that matter.

  12. Avatar
    tony about 20 hours later:

    the ruby example is so much cleaner and easy to read. php people are jealous because they->have->to->call->methods->like->this.

    really, your argument is childish at best and someone who is depress to bash a language in an attempt (be at a very bad attempt) to make their language of choice look better.

  13. Avatar
    Dan about 20 hours later:

    Some clarification for Ivantroll who is apparently well versed in neither PHP nor Ruby: those code samples are from the PHPSpec and RSpec projects respectively. So much for that "witty" insult.

  14. Avatar
    Steffen Hiller about 20 hours later:

    for ($i=1; $i<=20; $i++) { iWantMoreOfThoseComparisons(); // :-) }

  15. Avatar
    Robert about 24 hours later:

    Odd comparison. What's up with the comment in the PHP version not being transfered to the ruby version? Ruby doesn't support comments? Or you just trying to deliberately obfuscate the PHP version to support your point?

    Also, I'd suggest your post be titled "RSpec Didn't Translate Well to PHP". You are not demonstrating typical usage of either language. Makes for a pretty poor example to build a convincing argument around.

    What exactly is your point anyway? Your stated thesis is that PHP is like a factory and Ruby is like a playground. By itself, that statement is overwhelmingly pro-PHP. Ruby is just a toy, incapable of serious work? What other logical conclusion do you expect your readers to take?

    To really support your conclusion, your stated thesis should have been that creativity is more important than productivity. Even you should see how ridiculous that statement is though. Perhaps we should all use Logo from now on? Oh, that's right...Ruby is just Logo sans the turtle graphics.

  16. Avatar
    Kurt Schrader about 24 hours later:

    Clearly whatever point I was trying to make is being overshadowed by the code samples I threw in here.

    Sigh. Live and learn, I guess.

    For sake of reference, the code samples were copied directly from the front pages of http://rspec.info/ and http://www.phpspec.org/

  17. Avatar
    Robert 1 day later:

    By the way, this is the PHP equiv to the Ruby you posted:

    class DescribeBowling extends PHPSpec_Context {
        function before() {
            $this->_bowling = new Bowling;
        }
    
        function itShouldScore0ForGutterGame() {
            foreach (range(1, 20)) $this->_bowling->hit(0);
            $this->spec($this->_bowling->score)->should->equal(0);
        }
    }
    
  18. Avatar
    Christopher 1 day later:

    This article and several comments are just silly. The idea that one example just looks cleaner or more elegant is really personal opinion. And it is an opinion that only a tiny group of vocal programmers seem to find really important. It is like saying that this article would have been much more elegant if it was written in French.

    Even stupider is that the example that you picked was from a project that is trying to copy Rspec using PHP. Ports rarely seem as nice as the original to people who learned the original first. Even then the two examples are very close. The PHP one is actually implementing dynamic method names which is pretty cool, as opposed to Ruby's slightly hacky it/do syntax that uses a string.

    Instead of making silly comparisons, why don't you ask the author of that PHP code about the real difference he experienced during development. He is a very smart guy and like most PHP programmers has a positive attitude about Ruby.

  19. Avatar
    Kurt Schrader 1 day later:

    Man, I let this one get away.

    The point that I meant to make was that Ruby, as a more expressive and malleable language, encourages a greater amount of creativity and risk taking while one is coding, which has both upsides and downsides, and that I fall firmly into the creativity camp.

    The example is clearly distracting everyone from that point.

    On the upside, the trolls are out in full force. :-)

  20. Avatar
    haz 1 day later:

    Can you shut up already about language comparison.

    I am a ruby programmer but I am also a java programmer and a php programmer. The only difference is I don't compare them. I use them when it's necessary.

  21. Avatar
    Luke 1 day later:

    @Robert: I do far prefer your code to both the initial Ruby example, and the initial PHP example.

    This may just be the opinion of one person, currently working predominantly in PHP, but Ruby looks like trying to write code in the kind of language you use to try and explain something complex to a child, rather than the clear and business-like language of PHP.

    But, as I said, that might just be me, and if anyone wants to disagree with me, you're welcome to do so, but then again, no-one's being forced to read my code, so why should it matter to you?

  22. Avatar
    David Madden 1 day later:

    Will you ever dare to compare the two again? It's the equivalent of dousing yourself in petrol and telling the PHP guy with the matches to go f**k himself!

    I think the point in the original post though was spot on. Great people can produce great things with PHP. PHP is quick to pick up and quick to get going with and produce something. It is also easy to use badly (as are most languages).

    Still its always interesting to see implementations of similar actions in different languages. Good post.

  23. Avatar
    Si 1 day later:

    Ruby *is* better than PHP (and Rails is a bazillion times better that Cake/symfony/ZF).

    I know because Sharon told me that her mum says that your mum says that her mum says that your mum says so. So it must be true.

    nyeeeeeeeergh!

  24. Avatar
    Daniel 1 day later:

    @haz: Agreed.

    A lot of Ruby (particularly RoR) developer time is wasted trying to "evangelize" the pagan PHP developers, when many PHP developers (a) already recognize the successes of Ruby and (b) use PHP in the areas that PHP is intended/best at, and use Ruby/Python/Perl/What have you in their areas of expertise.

    The more RoR developers (and I mean RoR, generally Merb devs don't have their heads stuck up their own asses and laugh at other who don't have their own "creative hats") attack PHP, the more childish they make RoR (and Ruby by proximity, collateral damage) and the more they marginalize their darling language and the more they polarize and fracture the programming community. You don't want a polarized and fractured community because then it becomes a game of numbers, and dearies: you can't win a game of numbers.

    However posts like these, when not given from a soapbox, are very interesting and educating IF they can present language differences without resulting to personal attacks like "PHP DEVELOPERS AREN'T CREATIVE!" etc. etc.

    However I hope you are satisfied with yourself. The more posts like this I read, the less I even want to try to use Ruby, and I guarantee you I'm not the only one who feels this way.

  25. Avatar
    Tw 1 day later:

    Quick someone send a tweet on twitter...

    Oh I just remembered, its down again... Looks like it cant handle the pressure of the real world...

    Remind me again who those small start ups are running PHP... Oh yeah... Yahoo, Facebook, Wikipedia... Just to name a few...

  26. Avatar
    Christopher 1 day later:

    "The point that I meant to make was that Ruby, as a more expressive and malleable language, encourages a greater amount of creativity and risk taking while one is coding"

    Whether your example was distracting or not, still does not make your statements true. All you are actually saying is that you like Ruby better. Making nonsense statements like "more expressive, "more malleable," encourages creativity," and "encourages risk taking" about a wonderful language like Ruby is the actual trolling going on here.

  27. Avatar
    Kurt Schrader 2 days later:

    Come on everyone.

    A Porsche and a Prius are both cars, but clearly they have different strengths, a different feel to them, and a different community of drivers around them.

    That feel and community influences how you operate them.

    You can argue all you want about how they're just cars and they can be used in exactly the same way if you want to, but that's not what I'm doing here. I'm pointing out that they feel different and have different strengths.

  28. Avatar
    Mike 2 days later:

    Write the same code sample in an assembly language and compare how it reads to either sample. Do you find it easier or harder to understand, simply by looking at the code, what problem it is trying to solve? How many lines of code did it take to solve the same problem? How much of the code had to be added for housekeeping purposes?

    Will anyone accuse me of being an Assembly troll if I suggest that both PHP and Ruby are more expressive than Assembly?

    I would argue that Python and Ruby and a whole slew of other languages are more expressive, etc. than PHP. The example makes the point. There is less syntactic cruft in the Ruby example and the amount of code is smaller and maps closer to the problem.

    The "20.times" iterator in Ruby vs the "for( $i=0; $i<=20; $i++)" loop in PHP is a simple but great example of this. The first expresses better the intent. You want to do this 20 times. The second is a language specific looping construct that requires you to declare a variable that serves no purpose other than housekeeping for the for loop.

    I'm not out to "convert" anyone. Whatever floats your boat. I believe the author had some valid points, though.

  29. Avatar
    Rohit 2 days later:

    No wonder there are more companies(Yahoo!, Wikipedia ...) developing their applications in PHP. Because all the Ruby developers are out whining about why nobody cares about their beloved language. The best way to achieve your goal i.e to give Ruby the spotlight is build applications that beat their PHP counterparts. Like why not build a blogging engine that's better than say - Wordpress ?

    Aha! I bet 80% of you Ruby developers who keep whining about PHP is not a good language haven't written a single Application worth mentioning about - you want to know why ? Because real developers KNOW that you gotta use the right tools for the right jobs.

  30. Avatar
    Xr 4 days later:

    Congrats, I thought Ruby looked okay and you just managed to make me change my mind (actually, no, because it takes more than a blog post to change my mind but you get the point).

    That said :

    • Even if I started programming with Pascal, I still prefer braces over keywords for blocks.
    • That code snippet is horrible. At first, I thought it was because of Ruby, but the PHP code is equally horrible and my bet is that even with a perfect language it would still be awful.

    I'm not asking you to have the same skills as Knuth but please, when you try to make a point, at least show a proper example and not something that you thought of in thirty secs because you wanted to troll.

    Rohit: the very blog you just wrote in is powered by typo, which is a blogging engine written with RoR...

Comments