Remember Gregg and Jason in their Ruby on Rails vs PHP clips? The Rails guy goes to the beach while the PHP guy still tries to switch databases. Turns out hundreds of people die every year on beaches whereas the risk of dropping dead on your desk is next to nil. In fact, driving to work and most things you do during your spare time are far more life threatening than working on code and therefore the longer it takes, the better for your own personal safety.
Programming languages without a semicolon at the end of each line are like a fish without a bicycle. Nuff said.
Unless you’re workin on a project of your own, producing as little and maintainable code as possible will mainly DRY up your paycheck. You spend less hours copying and pasting, less hours fixing the same bug on ten different lines and less time finding bugs in the first place. But remember: Time equals cash when you’re contracted by the hour. So we should be grateful for PHP and frameworks like Zend which make it so ridiculously easy to write the most cumbersome code full of duplications.
Colliding classes which happen to have the same name can indeed become a problem, however, Ruby-style namespaces with module MyNamespace are by no means the only solution. The makers of PHP chose not to overload it’s lean syntax with such unneccessary keywords and urge coders to prefix the class name like class MyNamespace_MyClass instead.
Nevertheless, in order to satisfy those who still long for namespaces, PHP will support the namespace keyword as of the yet to be released version 5.3.
The presence of a goto language construct has been considered evil for decades now, yet not the keyword itself is evil but what a tiny minority of coders would use it for. In other words: Messy software developers are used as an excuse to discriminate the Methuselah of keywords.
Discrimination is fundamentally wrong! The makers of PHP have realized that and will will support goto as of the upcoming version 5.3 whereas for Rubyists the ruby-goto library (categorized Library/Evil) is not even available as a gem.
Cascading if clauses contain at least one “else if” case, so the natural way to name this keyword is elseif – as does PHP. Ruby on the other hand uses elsif which is so much harder to remember.
Ruby is a highly dynamic programming language which allows you to twist and tweak almost every aspect of it. Therefore all it takes is for someone to accidentially monkey patch the + method of Float and your application goes kaboom. PHP on the other hand has a rock static foundation which means array_uintersect_uassoc() does exactly what it sais, which is… well, check the documentation for that. And if you absolutely must change it’s behaviour, you can always write your own my_array_uintersect_uassoc().
Andy Jeffries compares the following snippets in his blog post 4 Reasons why Ruby Syntax is Better than PHPs.
PHP:
$foo = array("zulu" => "1", "alpha" => "4", "golf" => "8", "bravo" => "3");
$keys = array_keys($foo);
sort($keys);
$bar = array_slice($keys, 0, 3);
Ruby:
foo = {"zulu" => "1", "alpha" => "4", "golf" => "8", "bravo" => "3"}
bar = foo.keys.sort.slice(0,3)
Admittedly, the Ruby syntax is more elegant and easier to read. However, if elegance is your aim in life, you’d better become a poet. Fact is that my granma could read and understand this piece of Ruby code whereas it takes a lot more expertise to figure what the PHP snippet is doing. Software developers should face the fact that they are paid for expertise, so making things hard to read – best coupled with poor documentation – will make you less disposable on the long run.
The statistics of available extensions as of 2009-06-04:
| Language | Appearance | Extensions | Ext per Year | Sources |
|---|---|---|---|---|
| Perl | 1987 | 15461 distros | 703 distros | CPAN |
| Ruby | 1995 | 7326 gems | 523 gems | Rubyforge and Github (forks not counted) |
| PHP | 1995 | 749 packages | 54 packages | PEAR and PECL |
At first sight this seems to be bad news for PHP as it falls way behind the others with Ruby closing in on Perl. Then again in the real world with real customers it’s much easier to get a fair price for your software project if you can sell bits and pieces with: “There is no solution available out there, we’ll have to do it ourselves.”
You just have to learn how to sell them, too. Don’t believe the “half a product, not a half-ass product” stanza by the nice yet overly idealistic folks at 37signals (Getting Real, chapter 5). The real buck starts flowing once you force your customers to constantly upgrade or even contract your consulting services.
This said, PHP is the ideal choice. There are testing frameworks out there, even BDD has made it to the PHP world, but fortunately the PHP syntax is twisted enough to make the descriptions quite illegible. Compare the code samples from the two project webpages:
require 'bowling'
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
require_once 'Bowling.php';
class DescribeNewBowlingGame extends PHPSpec_Context
{
private $_bowling = null;
public function before()
{
$this->_bowling = new Bowling;
}
public function itShouldScore0ForGutterGame()
{
// allow 20 throws
for ($i=1; $i<=20; $i++) {
$this->_bowling->hit(0);
}
$this->spec($this->_bowling->score)->should->equal(0);
}
}
By working with PHP you can rest assured that 99.9% of the lines of code out there won’t come with tests and given the syntactical challanges that’s not going to change. Therefore, PHP is the perfect ecosystem for bugs to grow and continue to play an important role in selling bugfixing to customers.
Comments
This is really cool, didn’t read something this funny i ages, not even on 1st April :-)
The delivery is so dry that it almost comes off as serious. Very nice.
Funniest post ever! :) Have you ever planned in presenting it on ComedyCentral?
best. post. ever.
you are my new favorite person.
Thanks for the mention ;-)
(and no, I wasn’t googling my name – it came up in an RSS feed I subscribe to and I was interested – thinking you were being serious)
Funny article, and I agree with everything. But to be fair regarding #9, you can’t really limit PHP to Pear. If there is one thing that makes PHP easy for beginners, is that there is so much (crappy) code out there to copy and paste.
At the risk of being pilloried by both the PHP supporters and the Ruby supporters, according to search.cpan.org there’s over 67,000 modules in CPAN. At 523 Gems per year Ruby still has a long way to go to catch up to Perl (although at the rate Perl mongers are deprecating old fashioned modules, Ruby might only have to stand still). (See chromatic’s Modern Perl comments)
Re: That’s an interesting observation, indeed. The complete list of modules on CPAN shows a much lower (but still growing) number.
First, you should know that I’m entirely pro ruby. However for point 8, I don’t agree.
$bar = array_slice(sort(array_keys($keys)), 0, 3);
It’s as easy to read as ruby when you’re used to it ;-)
Re: Unfortunately that won’t work because sort() returns a boolean and not the sorted array.
> Re: Unfortunately that won’t work because sort() returns a boolean and not the sorted array.
No problem at all: $bar = array_slice(my_sort(array_keys($keys)), 0, 3);
Ah, cracked me up .. thanks for putting a smile on my face dude.. linked
Is it my impression or some Ruby and other language developers still have a deep envy of the success and dominance of PHP on the Web? ;-)
Dont’t be evil, get over it! ;-)
CPAN now has 17488 distributions, each containing many modules (67343 total). I don’t know much about the ruby community, but what do you get when you upload a gem to rubygems? On CPAN, you automatically get world mirroring, smoke tests on many platforms (reports, statistics), a bug tracker and forum for your dist, among other things.
Re: This explains the difference in numbers, thanks for the enlightenment!
Ah, and I know this post is about PHP and Ruby, but in Perl it would be something like: @bar = (sort keys %foo)[0..2];
Re: Touché ;-)
The best summary ever why PHP is still better than Ruby, I laughed a lot :)
I started ruby today, yet some how I still understood your jokes. I guess it must be because PHP has just been so good to me over the years.. :)
I stop TODAY doin’ ruby.
Well I will go back to PHP, nope, the best of the best: interpreted basic with no object at all, no classes, and plenty of goto. Hum… maybe cobol is still alive. My preferd was APL in the 80ies, a succession of hieroglyph (ancient egyptien), totally unreadeable (1 charracter=1 function and you can’t associate the character to an a or a z, its hieroglyph), that’s good for building a dynasty of bugs and fixes….You can’t read your own code, how can somebody else?
Ruby is for trolls and newbs. It’s a great language, but not for the web. period.
Re: Because the web consist of 90 percent crap, not the right habitat for any great language.
Man, changing from PHP to Ruby was the best thing I’ve ever done. Made my life about 500 times easier, less stress, and more fun!
I like the fact that you get more done, in less time, with clean(er)/revisable code. More pleasure, money. Also the whole “Convention over Configuration”! No need to think about stupid things, also better when working in a team, without annoying anti-social asswipe programmers that only go by their own rules! I’m glad I stepped out of that world!
Nice post by the way.
Ruby is a nice language and all, but can it run big sites like Facebook?
Re: Seriously, how many Facebooks have you coded? On a more realistic scale: Github is a Ruby on Rails app. And here are a few more examples.
How fast is it compared to PHP?
Re: Ruby vs PHP performance
Can I easily extend Ruby with C++?
Re: Ask Google.
Also, is Ruby used widely enough so that I can easily find resources for building stuff with it?
Re: Absolutely, Ruby has a very active and helpful community. Stay tuned, I’ll post my linkroll in the upcoming days. For now, check out Rails for PHP developers where you can search for PHP commands and get snippets comparing the corresponding PHP and Ruby/Rails API.
Sven, try building a big website with Ruby. Try hiring Ruby developers, if you can find them and then come back and tell me how much better you think Ruby is.
Re: Well, Wayne, that’s what I do for a living. Besides: Many Ruby devs have worked with PHP for years – can the average PHP dev say the same for Ruby? I sincerely encourage you and any skilled PHP dev to put aside prejudice for a moment and to give it a shot, you might actually like it.
I like that you finally began writing blogs! It’s hellot of fun. Thank you so much,... I didn’t care about WHY I changed to ruby, or let’s say, I try… PHP habitat is still so big, I get to much work on this side. But fortunately, I manage to convince my clients to let the PHP thing behind and discover new agile ways…. more and more…
10 Reasons why PHP isN’T Still Better than Ruby ;-)
very nice post!!!
Bookmarked it. Shall read it over and over again to laugh.
I’m not 100% sure, but I think I detect some sarcasm. Or maybe irony. Yep, that’s it.
Nice and funny post. One more reason to still learning Ruby.
As a 5+ year PHP developer, and a web programmer (in Perl and Java as well) for almost a decade, now moving to Ruby (thank heavens!), I can honestly say: this is dead on. PHP is a garbage language that throws so many potential bombs and time-wasters at developers that it should really have been taken out back and shot years ago when it was first stillborn. And the addition of Java-style OO syntax in version 5 just makes it more stupid and inelegant. I can’t wait until PHP dies and goes away forever. I started with Perl, enjoyed it, and then cursed every day I coded in PHP…and now I have Ruby. It’s a relief.
Oh, and as far as “can you build Facebook with it” nonsense, you can build Facebook or anything with any of these technologies, even languages like PHP…smart developers can build good apps with most anything.
But the real question is: how much of your developers’ time does a programming language waste? Ruby tries very hard (and largely succeeds) – especially with frameworks like Rails/Merb – to not waste developers time, and help them expend brainpower in the right ways. It’s superior in this way to PHP.
bah, a language vs. a framework, compare rails with symfony, cake, ci, etc, don’t be fool
Re: Not really, unless you count the reference to the clip by Gregg and Jason. Then again, “Half the Features, Twice the Fun: 10 Reasons why Copycat CakePHP is Better than Rails” – sounds promising.
This is what I don’t get about developers… Everyone points their scrawny fingers to other languages and labels them “Witch” languages. How about you try both? If you like one over the other then great! but lets say for one second that you liked both… wouldn’t it be great experience to have under your belt and also know which to use for what job? seriously people ;)
Believe me, I have tried both. (10 years of PHP, even Zend certified.) The reasons for using PHP are non-technical, e.g. “the client insists” or “legacy system”. But coding doesn’t feel right the way it does with Ruby.
Hi, can you suggest on a decent book to start on? i would like to finish through a book before going for advanced stuff. i am tired of a lot of things with Java. I really feel a want to learn something new.
Re: Personally, I like David A. Black’s “The Well Grounded Rubyist”.
I’m for php.
Let’s face it, OOP is just not appropriate for websites, large or small. Mine turn over £2.5-3M (not that I get much of it), but the most important factor was speed to creation, not OO statergy.
OO rarely ends in reusability, whether it be implemented in c#/java/ror/php.
Unfortunately I dont’ believe Ruby will be there big time in 10 years from now i.e it will still be a small niche player.
I have played with ruby myself a little bit, on and off since 2006 , I know I am a late comer. these are my thoughts about Ruby.
1) after so many years, it’s still like 2% in the Tiobe ranking
2) its weak typing, many people have said this is an asset, but I don’t. agree. Weak typing is a dsadvantage in my experience (working with very large apps in a big Financial Institution, running 24×7 ). Rubyists have always countered with a “do more testing” approach , but I don’t agree this will catch all your problems. I believe you have to have strong typing combined with a “do more testing” approach is better, especially when you are working in large teams where every one can touch any code.
3) speed is still a problem after so many years, everyone knows it’s a problem and yet the community is so slow to address that.
4) by the time, the ruby language and framework, has fixed its problems, the fad will have died and tne crowd will have moved on to the next big thing.
5) features in ruby is being and will be copied in existing languages and new languages
6) there are too many ways of doing the same thing in Ruby and this is a disadvantage as well, as this means if you are working in a big team, you have to learn every little nut and bolt of the language to be able support an application. that means, the learning curve is actually higher. In a one man team this is ok, because that one man picks one style and sticks to it and doesn’t have to worry about other people’s coding. It’s like driving on the street, you don’t have to think if the car next to you is going to drive left or right, and this prevents accidents. can you imagine for one moment that people are allowed to drive left and right in any direction ? what will happen?
I am aware that Saphire is trying to redo Ruby, with only one way of doing things. maybe this will help.
7) I think it’s safer in terms of longevity of languages to stay with Java and .net. because at some point Ruby will be forked and a new variant with a lot of differnt things added, will come out, fragmenting the market even more, which will reduce the current 2% to even less.
8) the big institutions are not doing Ruby. only startups, with basic CRUD applications.
9) last but not the least, the absence of a specification hurts the language. by the time the specs will come out and “accepted” by the community, it will be too late. Languages like Scala will already be well established.
10) the community looks and acts too amateurish. I don’t believe even Sun’s and Microsoft’s presence will be able to change that. Unless they fork their own versions, in which case that will cause fragmentation of the ruby community, with its adverse impacts to the ruby community as a whole.
anyway these are my thoughts. sure people may disagree with what I said, but every one is free to one’s own opinion. Let’s wait and see, only the future will tell whether one is right or not
I came here actually expecting to read about serious advantages PHP has over Ruby.
Your main focus is the money you do and your old habits.
I mean do you have a real concern about Progress and giving your BEST to the people who hired you? – What is that talk about bugs are your friends? – What about trying new things and exploring new concepts?
Sure Ruby is far from perfect, but I read better reasons to prefer PHP in some comments, rather than in your original post.
Re: Writing satirical articles would be just half the fun if everybody got it. Get it?
If you just care about the easy money you make and not about efficiency, progress and evolution, saying you work in anything relating to computing, or web in particular, is basically an insipid oxymoron.
Very funny. Your vision are the definitive reason for me to learn ruby NOW.
Thanks from Spain!
Never coded anything besides some lines in Php on Wordpress (I said never) … yet I could understand the apt irony. Maybe that goes to bare C. C++ Skills but yet an amazing post whatsoever. Brillliant! :)
The title of this post should actually be “10 reasons why PHP is still better for professional developers than Ruby”. And by professional, I mean people who are paid to code, not developers who are just really good.
Good post though!
i like to use php for my client.. specially when the client are big company… however for my own sites i use ruby all the time
Sorry, but your text is really boring… Maybe some kind of amusement for scriptkiddies and all the “i-hate-PHP-and-i-don’t-know-why-i-just-do-it-cause-the-others-say-so” idiots but nothing more.
Thought first to read here something really funny but it’s the same “bla bla…, PHP is so bad and f*cking ugly and how were i used to write it for years and years” – sh*t like on any other sites….
You know, it’s not that you really don’t like PHP or something, but the point is:
If you don’t like something why don’t you use something else which makes you happy instead of investing that much time, effort and skills in showing the whole world WHY that thing you don’t like is so bad and useless ?!?!
Re: Well, ask yourself. You could have ignored this article but chose to read it and comment, why?
It’s like all the boring flamers and haters which daily flame aganinst Apple, Microsoft, Linux, Windows, and so on…
Re: Whereas you… It’s obvious that I’m not nearly as scintillatingly witty. Your wording is sublime!
If someone doesn’t like the iPhone, why don’t he use a Blackberry, Nokia or something else and will be happy? What is there behind the scenes that these people invest hours, days, months for sh*t like these?
Re: Because people like to share their findings, some by means of technical analyses, others in a satirical way. I apologize for boring you, however, I find your comment quite amusing, so it was worth it.
I don’t understand and i won’t even in future…
Anyways, good luck with your career or whatever you do… ^^
Re: Thanks, same to you… ^^
Hi, everyone – I’d greatly appreciate hearing your recommendation on this: If you were building eBay today from scratch, and are on a tight budget, but want to build it as fast as possible, would you use PHP or something else?
Looking forward to hearing from y’all!
Re: My weapon of choice is Ruby on Rails as it covers most of the essential needs to do rapid prototyping without imposing say the kind of database. Furthermore, the Ruby community embraces test/behavior driven development way more than PHP developers do. And without proper testing, you will sooner or later face a pile of unmaintainable code.
I believe that PHP is better than Ruby. But these 10 reasons are not rational. If a simple and readable syntax threaten your job then you are missing something to offer, it sounds like a lie, you could make easier and faster but prefers to do more complex and time consuming to charge higher values? The evolution that gave rise to the high-level languages did not disappear programmers.
Re: I honestly hope the sense of humour and technical expertise don’t sit in the same spot in our brains.