Will Ruby kill PHP?

August 7, 2006

With the recent rise in popularity of the Ruby programming language (largely driven by the excellent but not perfect web framework called Rails), I’ve noticed a little fear in the air … fear on the part of some people in the PHP community.

Will Ruby kill PHP?

The short answer is: no.

MY REASONING

Though Ruby and PHP are both scripting languages that make developing web applications much easier than it is, say in the Java world, they are very different beasts … each appeals to a different audience.

RUBY IS ELEGENT BUT COMPLEX

Before I go on, I want to point out that Ruby is a great language and I think it makes perfect sense for PHP developers to learn a little Ruby: it is always a good idea to learn other languages because it will make you a better programmer.

That said, I believe Ruby will not appeal to, or fill the need of most PHP’ers – Ruby can be a little too abstract.

JAVA NERDS LOVE RUBY

Ruby is attracting many from the Java world because it expresses very advanced concepts in a simple syntax – contrast this to Java’s (often times) kludgy and verbose representation.

Ruby appeals to the Java crowd because Java people have been trained to think in terms of large scale enterprise applications – regardless of the size of the project.

… These ‘abstractions’ (generally speaking) lend themselves well to larger projects.

WHY PHP WORKS

PHP is often criticized because it has both a procedural and an object oriented way of doing things. Some people think that this divergence (within the language), takes away from it … I think this is part of its strength!

Objected oriented constructs are great for creating cleaner designs that are easier to maintain and promote the possibility of code reusability. Code reuseability is an often touted advantage of OOP, but from what I’ve seen in the Java world, it is not achieved so often.

With OOP, there is a cost of added complexity and overhead – you simply have to write more code to do things when you do it via OOP.

PHP PROVES THAT NON OO LANGUAGES STILL HAVE THEIR PLACE

I would suggest that the vast majority of PHP work is found in simple projects:

  • Email from a web page.
  • Process a simple form and save to a database.
  • Create a simple store with 10 items.

My point is, that for many PHP projects, OOP may be a little overkill.

WHY RUBY WILL NOT KILL PHP

In Ruby everything is an object (even numbers!) and the core language has very sophisticated constructs that need to be understood to use Ruby effectively – Ruby strength is also its’ weakness.

… I don’t see the majority of PHP users wanting to jump that deep into the world of programmatic abstraction – for most, there is simply no point.

Stefan Mischook

34 Responses

  1. Pingback: PHPDeveloper.org

  2. php programmer Author August 9, 2006 at 11:34 am

    Based on your argument..do you indirectly hint that Ruby might be a better language for large-scale application development (considering its object-oriented approach)?

    Is there a benchmark that profiles large-scale applications built with Ruby on Rails (framework) against a PHP’s native framework? How does the R-on-R framework scale to larger loads? Just curious. Thanks.

  3. stefan Author August 9, 2006 at 11:49 am

    @php programmer,

    No, I was not meaning to suggest that Ruby might be better on the large-scale side of things. PHP OO is very capable and PHP has several Rails-like options in terms of web frameworks.

    Ruby is a very clean language and it has lots of things going for it. But PHP has lots of things going for it too. You can point out spots where Ruby code is cleaner than PHP, but you can point out spots where (I think) PHP code is cleaner than Ruby …

    Today I would consider PHP the better choice because it is well established (lots of IDEs, open source projects, easy hosting etc ..) and proven.

    Ruby is just starting to get into the mainstream … and there are still some fundamental issues with Ruby and web development.

    For example: Ruby integration with APACHE is still not stable. It works … but there are known problems and can be a hassle to set up.

    We’ve also run into problems internally (I have a Ruby project going as an experiment in Ruby and Rails) with Ruby and email … I am sure there will be other gotchas along the way, as you would expect with any maturing language.

    That said, Ruby is 10 years old.

  4. hamish Author August 9, 2006 at 8:12 pm

    I agree with what you said.
    OO is definitely overkill for a lot of web projects. It seems to me that so many people use OO frameworks like Ruby and Zope because “it’s enterprise level”. But using an ‘enterprise’ framework for small to medium sized web applications just adds so much overhead and frustration at having to learn the framework that it just doesnt seem worth it to me. Having said all this I must point out that I’m distrustful of large corporations and hate their dehumanising heirarchical structure. Therefore i am naturally drawn towards open source and away from the whole OO/enterprise/heirarchy paradigm. Maybe people want to push open source to the enterprise level in the hope that they will adopt the technology and therefore they will have more job security. Get over it – go and learn Java and .NET if you want job security and preserve open source software as an oasis of freedom away from the corporate world. Just my 2c. 🙂

  5. Overshard Author August 9, 2006 at 10:53 pm

    My 2 cents… LEARN BOTH… like he said in the artical learning multiple programming languages never hurts and will help you as a programmer in the long run so I tend to throw in as many programming languages as possible. Sure you may get them confused here and there sometimes but thats why you take notes along the way of learning. If you keep a record of what you do and how you fixed problems you are more then likely not to make the same dumb mistake again (ie forgetting a ; at the end of a line of php keeps getting me but doesn’t effect me in other languages… dunno why).

  6. hamish Author August 10, 2006 at 7:35 pm

    Yep, ‘Learn Both’ is great advice. But please please please choose the right technology to suit the needs of the application is all! Dont use a huge OO framework to make a simple site for a small company, just because it makes you feel good to be using a great big hulking technology. Happy coding… 🙂

  7. Pingback: » Reaction to killerphp.com » Blog Archive KILLERPHP.COM

  8. Mindilator Author August 16, 2006 at 5:55 pm

    OOP has its place, but the diversity of frameworks is just as challenging to figure out as a new class you didn’t write, if not more. None of them work the same or keep a standard convention between them that makes learning them easier. Frameworks are great, but sometimes I think maybe they don’t all have to be OO. I keep a small personal library of functions I’ve (and others have) written procedurally and include them just like I would a class. Beyond the overhead issues is complexity. OOP has you chasing declarations over many files to figure out what’s happening. If you’re trying to learn how that unique class you need works, it can be time consuming to read through it and see how the class is structured. By the time you’re done you may as well have written the class yourself, at least by then you’d have a solid understanding. Encapsulation and polymorphism have their advantages, but the cost is complexity which can equal time. And for smaller projects that will likely never expand, that time and energy can be a waste.
    Not trying to bash OOP, just to defend procedural style. They each have their place.

  9. Stefan Mischook Author August 16, 2006 at 7:42 pm

    The advantages of OO structures begin to shine as the project becomes more complex – forcing the use of OO in every trivial application is just a waste of time.

    The Java world is now trying to deal with the damage of over engineering software …. the PHP world would do well to learn from that mistake and learn to keep things as simple as they can be.

    @Mindilator: +1

    Ciao,

    Stefan

  10. Stefan Mischook Author August 16, 2006 at 7:46 pm

    I want to point out that Ruby lends itself better to OO based designed because it is an OO language from the ground up. Contrast this to PHP, where OO capability has been ‘bolted’ onto a procedural framework.

    This distinction may seem subtle but it has noticeable effect on the use of the languages.

    I will be exploring this is more detail soon enough.

  11. iGEL Author September 11, 2006 at 1:25 pm

    Hi!

    Sorry, but I don’t like your text, because you mix Ruby and Ruby on Rails alot. Ruby is in my oppinion easier to use then PHP, because PHP has no design-principle beside “make it work, somehow easy to use”. Ruby has some really cool stuff I miss quite often, when I have to program in PHP again (blocks for example), but has a more clear and logic syntax.

    Ruby on Rails is of course not that easy to use, at least when speaking about small-scale projects. This is, because it does alot more than PHP does. Of course, there are other good reasons to prefere PHP over Rails (like the better support by providers, more modules, more documentation), but from my opinion, most projects done in PHP from the complexity of a blog could profit from being programmed in Rails, from the pure technical point of view. At least I won’t program in PHP again unless a customer asks me.

    iGEL

  12. guardianblue Author October 20, 2006 at 10:10 am

    Will Ruby on Rails be too ‘large’ or too ‘enterprise level’ for small web projects?

    I don’t really think so, as I can see although that the Rails development team have consider many aspects that you will come across with web development, you don’t need to learn ALL of them before you can start building a web app.

    After building several of my projects with Ruby on Rails, I found out that it greatest feature is the seamless integration of Object-Relational Model Mapping. With Rails, you don’t even need to have much knowledge on SQL, which reminds me of those PHP and Java prepareStatement nightmares.

    There are also some great PHP web-app frameworks on-going, like Cake and Symphony, but before they can be comparable to Rails, much works on completing the documentations are really need to be done.

  13. zima Author April 4, 2007 at 11:11 pm

    You dont have to use OOP in ruby! You can do it PHP way! So you better do your homework before making such statements!

    What is really OVERKILL to me, is to know the hundrets of functions, PHP provides out of the box, and avaliable in ANY scope! So I have to be extra carefull wheter I can use some name. And the more functions – the bigger the MESS.

    On the other hand, in ruby you use only functions avaliable for particullar object you use.

    I would rather say: “some text”.length than strlen(“some text”); which is much more meaningful! Ruby language itself much more descriptive. I remember myself, from my old PHP days, heaving alwayse to look up the php.net for appropriate function, but now I can just guess!

  14. Nate Klaiber Author August 10, 2007 at 3:29 pm

    I think you presented this case very well. No bashing either way, just clear points to strengths and weaknesses. I program both and love both languages. I think they both have their place, and, as you said – for smaller tasks PHP is the ticket. If i need to create one-off stuff for email or even small database, then using Rails – or Ruby, would be overkill. I think over the years people go back and forth about PHP. Some think that PHP is a procedural mess, and it does have the ability (just look at some code samples around the web). However, that is also it’s beauty. You can easily achieve smaller tasks with less overhead by taking advantage of the procedural aspect.

    Not everything is enterprise or needs objects. Yes, OO helps keep things clean and abstracted – but it simply isn’t the model for every site out there.

    I won’t go as far as to bash either language. I love them both and enjoy programming both – and I think you have clarified their purposes in this article.

  15. Shadowfiend Author August 12, 2007 at 2:04 pm

    Yes, while Ruby is OO through and through, you can code procedurally in it. The neat thing for me is that even when you’re coding procedurally, you’re secretly coding OO (you write private functions for the Object class, which makes them behave exactly as they would in a procedural sense).

    And keep in mind that there are other, smaller, less intensive frameworks for Ruby, including Camping and Merb. These don’t necessarily provide all the extra magic that Rails provides. Plus, you can theoretically just use straight erb to make Ruby for the web be exactly like PHP for the web — just an interpolation of Ruby code with HTML (with the ability to include files, etc, etc).

  16. Robert Author August 12, 2007 at 7:47 pm

    No, because PHP is too entrenched and Ruby is barely on 1% of the shared web hosting servers. I have not seen the “rise” in the use of Ruby either. In fact, the “hype” has died down quite a bit.

  17. Stefan Mischook Author August 13, 2007 at 4:17 pm

    I want to be clear that the point of this article was not to bash one language or another.

    Instead, I was honestly trying to answer the question suggested by the title of this article.

    That said, I believe that for most projects, PHP is the language to go with these days.

    … This could change at some future date though.

    Stefan

  18. Pingback: Will Ruby Kill PHP? « FlashColony webmaster’s blog

  19. Michael Author August 16, 2007 at 7:06 pm

    Python will kill’em both

  20. Dan K. Author August 17, 2007 at 4:43 am

    So you would use non-OOP principles on a store with 10 items? Man, it’s not about items at all, it’s about the representation of real world entities and things people do with them and from that POV I don’t see any reason to use non-OOP on creating a eshop whasoever… You only prepare yourself a hell. Writing slightly more code is a hell of a low price… I don’t talk about MVC frameworks, you don’t have to use them. Write plain PHP. But use objects.

    As Michael said, Python will kill’em all 😉

  21. Stefan Mischook Author August 17, 2007 at 8:25 am

    Dan,

    I appreciate your point – and do agree most of the time OO methods are the way to go.

    That said, whether that particular example is better served with OO methods or procedural methods is a matter of debate; my point is that there are times when a simple and quick procedural implementation is suitable.

    Python:

    Is a nice looking language. But I haven’t used it in real projects so I can’t comment far beyond ‘Hello Word’. Bruce Eckel (author of ‘Thinking in Java’) I remember, really liked Python and looked to it as a template for where Java should go.

    I have used some Python based applications that, though very well designed, required a lot of juice to run … Python seems to needs lots of CPU.

    But again … I haven’t tested this thoroughly.

    Stefan

  22. Zsolt Author August 17, 2007 at 9:31 am

    I have a reasonable level of experience with PHP and Python but unfortunately haven’t touched Ruby yet. They both seem to be a good choice for low complexity projects. I can even say that I like Python a lot. But I would never consider it again for projects where design is an issue. They also say it is for (rapid) prototyping. My experience is that as long as you can’t afford a proper IDE Python is maybe the best place to go to. But a properly “equipped” environment can formidably boost your productivity with a statically typed language like Java. In that case Python’s advantage shrinks to the benefits of quick tests accesible through its command line.
    Another problem of Python is that it wants to be everything: simple and complete, flexible and structured, high-level while allowing for low-level programming. The result is a series of obscure features
    Having said all that I must give Python all the credits of a good language. It’s just not perfect. Maybe it’s Ruby 🙂
    My apologies for not sticking too closely to the subject of the article.

  23. shoof Author August 17, 2007 at 10:16 am

    Ruby has a long way to go, I can’t argue for the programming details as I still like my Perl but from the SysAdmin side Ruby and Rails for the matter are an absolute nightmare.

    Ruby in itself is slow, doesn’t understand threads like every other language out there so it doesn’t integrate into apache like PHP or Perl or Python or the other hundreds of web scripting languages.

    Until Mongrel came out you were forced to use fast_cgi, which is a dead method of rendering pages, apache’s mod_fcgi is crap and lighttpd’s fcgi is better but the server itself is not stable enough for production.

    Ruby has to start by modernizing it’s preprocessor before it even has a small chance in hell of overtaking PHP and even then Rails has a long way to go before it’s ready for the primetime, the ease at which a programmer can cause Rails to leak memory is astounding.

    I have a shared server with 40 Rails sites running and I have to restart them every week or the box swaps and that’s with 4G of memory, most of these sites aren’t even that intense. On the other hand one of my mod_perl servers has over 100 ecomm type sites and they run just fine of 2G.

    So the answer is no, Ruby will not overtake PHP in the distant future.

  24. DjDarkman Author August 17, 2007 at 10:52 am

    The one thing I hate is OOP geeks trying to prove that they can write code that does nothing usefull and nobody understands.

    “You dont have to use OOP in ruby! You can do it PHP way! So you better do your homework before making such statements!”

    Then why use ruby in the first place?

    “What is really OVERKILL to me, is to know the hundrets of functions, PHP provides out of the box, and avaliable in ANY scope! So I have to be extra carefull wheter I can use some name. And the more functions – the bigger the MESS.”

    On the other hand, in ruby you use only functions avaliable for particullar object you use.

    I would rather say: “some text”.length than strlen(”some text”); which is much more meaningful! Ruby language itself much more descriptive. I remember myself, from my old PHP days, heaving alwayse to look up the php.net for appropriate function, but now I can just guess!”

    Yeah you must have weak memory and can`t remember wheter strlen() is for strings or for numbers….

    Doesn`t ruby have the same number of functions just stored in objects?

    Look if you can`t remember strlen than invent your own classes you can make a whole useless OOP framework for PHP in a day……

  25. Stefan Mischook Author August 17, 2007 at 11:06 am

    What made me choose PHP over Ruby was the underlying fundamentals:

    1. PHP is faster.
    2. PHP is mature.
    3. PHP hosting is easy to find and consistent.

    I was worried that I would be halfway into a project and find myself having to drop down to C to get something done because an aspect of the Ruby language was lacking …

    Or worse, I was worried that we would have tremendous problems getting Ruby to play with Apache.

    … We have our own web servers for various reasons and so we had to be sure that our own crew could manage Ruby. We fuddled for a bit, but quickly ran into installation and speed issues.

    Stefan

  26. Stefan Mischook Author August 17, 2007 at 11:17 am

    Regarding PHP’s perceived lack of structure:

    PHP is now object oriented, it has web frameworks similar to rails (you several to choose from) and has ORM.

    … PHP has some legacy issues (inconsistent naming of functions etc …) but to me, they are minor distractions from a much larger and more important picture: PHP is not what it was years ago.

    In fact, I found the Zend Framework to be a nice structure to work with. We used it to help build a new video sharing, social networking site (http://www.idea22.com) that is totally modular.

    We are still in beta (and are tweaking many things,) yet at this early stage we can drop components in and out the framework and even introduce major new features into the application relatively easily … as we will be over the next couple of weeks.

    Stefan

  27. Chandru Author August 18, 2007 at 7:20 am

    Guardianblue, developing with Java need not require knowledge of SQL (ever heard of Hibernate or persistence in EJB 3?). Development of enterprise applications with Java is also much simpler with the introduction of Java EE 5. I strongly believe that the world must take a look at Java EE5 before commenting on the Java platform.

  28. Kamilion Author August 19, 2007 at 5:26 pm

    At the moment, I’m learning both PHP and Ruby on Rails.
    One of my favorite things about PHP is being able to mix OOP and procedural code. It’s really handy to build an OOP class, and then use it procedurally.

    My current application is a mix of PHP and Ruby on Rails.

    I’m using Rails to build the web frontend and mySQL interaction, and I’m using PHP to expose the database as a text backend to an object in Second Life. Works quite well, as long as I keep the schema that rails is using updated in the PHP code; but the PHP application is only 4 classes and a dispatcher, so it’s not that hard.

    Both have their uses. The real key is knowing which to use where.

    Rails is awesome for user interaction, and PHP is invaluable as a backend interface where I need to specify things my own way; rails’ sensible defaults are useful, but can get in the way when you *need* to do something a little differently.

    In my case, I’m limited to a 2048 byte reply, so I have to go with text only replies.

    Rails can do text, but it’s a pain in the butt to dispatch a text list of instructions in the reply due to the output view templates. PHP does much better at this with procedural generation of the list using objects for scatter/gather of data and exposing the gathered data in whatever order I need; some returns require 5 lines returned, some require 17, some even more!

    Rails can’t do this as well due to it’s strict adherence to MVC and DRY.

    The way I’ve written my client, PHP generated instructions can be processed in any order; but rails forces me into a strict order due to the view template.

    I realize I could use partial renders to build up a page, but it’s actually taken me less code to do it in PHP.

    Anyway, that’s just my opinion — Make a choice for yourself and use what you need!

  29. Alice Author August 21, 2007 at 4:27 am

    As an experienced developer in both Ruby an PHP I subscribe the above statement that you’d better learn both of them. It will make you a better developer.

    I’ve leaned a lot from Ruby on Rails in terms exercising my neurons to avoid unneeded code.

    The main Ruby advantage is that the first serious web framework made available (RoR) glued up all the design patterns that the Java community was still trying to understand in a simple to use and understandable manner.

    PHP on the other side has far too many so-called frameworks that are popular but miss the simplicity approach to design patterns that Rails has.

    Now I’m trying the Akelos framework, which has really ported Rails simplicity to PHP (not like Cake and Symphony). The most important reason for moving to Ruby, has now an alternative on PHP, so this might decrease the avalanche of people leaving PHP for “Rails”

  30. Pingback: GfxDizayn » Başlıksız-8 Eylül 2007

  31. PHP developer Author September 12, 2007 at 11:10 am

    I don’t think that Ruby can kill PHP, why I’m saying that. Now I’m using agile web development with rails on Ruby. My experience says , PHP and smarty can be used to develop Rails. it is just a matter of management and I’m sure will hear about Rails using PHP soon,
    Best Regards

  32. timtux Author October 21, 2007 at 7:38 am

    I recently switched from PHP to Rails, and nowdays i hate PHP, rails is the way to go.

    Just a thing as pagination of posts, in php? Atleast 50 lines of code. In rails?
    “@posts = Post.paginate :per_page => 5, :page => params[‘page’], :order => ‘created_at desc’ “. Yes, thats all.

    My weblog contains 305 lines of code. Tagging, Posting, Signup, Tagcloud, Comment, Administration, pagination. How long is yours in PHP? 🙂

  33. Stefan Mischook Author October 21, 2007 at 9:07 am

    You are comparing apples to oranges.

    … If you want to compare Rails to something, compare it to the Zend Framework or CakePHP or some of the many other PHP based frameworks that provide the same functionality as Rails.

    Meanwhile, good luck getting Ruby to work well with Apache …

    Stefan

  34. Pingback: » What happened to Ruby? And why PHP is KING of the Web. » Blog Archive KILLERPHP.COM

To Top