Should I switch from PHP to Ruby?
December 4, 2005 12:55 PM   Subscribe

Should I switch from PHP to Ruby? I know this topic has been covered before, but I have some specific questions that I haven't been able to find answers to, here or elsewhere: 1. How complete are the Ruby libraries? and 2. How is Ruby's performance compared to PHP?

I've been using PHP for about four years. I'm writing a storefront/content management web application that I hope to be able to peddle as a freelancer. It's just me, so I can do whatever I want.

My specific questions are as follows:

1. How 'complete' are the Ruby libraries? I have never run across a problem I couldn't solve with PHP, and I'm worried that if I make the jump to Ruby, I'll suddenly find myself having to exclude functionality. For example, in PHP I can write PDF, Word, and Spreadsheet documents on the fly, and I can create and manipulate images on the fly. Have any of you made the switch, and then smacked your forehead when you realized you couldn't do something that you used to be able to do in PHP?

I've heard some advocates of Ruby say that one reason they like Ruby over PHP is that in PHP the fact that you can do whatever you want leads to "spaghetti code". Obviously messy code is bad, but I think that the fact that PHP *allows* messy code doesn't mean that messy code is inevitable. Anyway, this sort of argument makes me wonder what exactly Ruby is going to prevent me from doing.

2. How is Ruby's performance compared to PHP? With the exception of some crazy bad MySQL queries I wrote a few years ago, I've never had problems with performance issues on my LAMP sites (but I don't have millions of page views per day, either). I have, however, seen speed issues cropping up with, for example, Backpack, which I've been using as my task manager. Now, that could be due to the unexpected popularity of the site, or due to too-heavy ajax use, or to any number of non-Ruby issues. I just don't know. Most of the performance comparisons I've seen are between Ruby and Java.

Thanks!
posted by jay.jansheski to Computers & Internet (22 answers total)
 
I played around with Ruby on Rails, and it's so damn immature compared to PHP it's not even funny. The brilliance of PHP, in my opinion, is the insane number of libraries and functions just built in, and the number of and ease of adding additional libraries.

If you're a code snob, or want to play with bleeding edge stuff, Ruby (and more accurately, the Rails framework) may have something for you, but if you want something to get the job done, and you know PHP, stick with it.

Typically, performance issues with database-driven websites are due to a poor database schema, or in certain high-load cases, the database itself. Rarely is the scripting language the bottleneck. (And if it is, it's also by far the easiest bottleneck to work around.)
posted by trevyn at 1:23 PM on December 4, 2005


Notwithstanding trevyn's statement, which I do not deny or confirm, for lack of knowledge on my own part...I've never ran into something that I (as someone who switched from Perl and PHP) couldn't find. Gems are what you need to look into for those libraries.

gem.rubyforge.org currently lists 587 unique gems for download and install. *shrug* If you can't find what you need, are you thinking that your requirements are really all that unique?
posted by Kickstart70 at 1:45 PM on December 4, 2005


Regarding 1: There isn't as much in the built in library, but IMHO this is a good thing. Better to build everything from a relatively small collection of basic tools than to rely on PHP's sprawling library of random quasi-useful functions with no discernible naming convention. (isset() verses empty()? strtotime() verses ip2long()? what the hell is date_sunset() even doing here?) It's the difference between knowing how to systematically solve a logic problem and rote memorization of other people's solutions.

Regarding 2: I wasn't able to find any benchmarks but I suspect Ruby is measurably slower. In all likelihood though, either way you go the bottleneck is most likely going to be in the database anyway, so it's probably a moot point.
posted by moift at 2:15 PM on December 4, 2005


heh that was a little redundantly redundant, I just wanted to make extra sure I got the qualifications in there :/
posted by moift at 2:17 PM on December 4, 2005


I played around with Ruby on Rails, and it's so damn immature compared to PHP it's not even funny. The brilliance of PHP, in my opinion, is the insane number of libraries and functions just built in, and the number of and ease of adding additional libraries.

Just wanted to post to let the person asking the question know that the above is a pile of FUD.
posted by wackybrit at 2:32 PM on December 4, 2005


I don't know a lot of these things, but I recently listened to two ruby-loving friends bitch about how Ruby on Rails is a lousy piece of software that is essentially the opposite of straight-up ruby.
posted by I Love Tacos at 2:46 PM on December 4, 2005


Do you want to be a better programmer? Do you want to extend your skill set outside of just web programming? Those are both good reasons to learn a standalone language like Ruby.

In addition, I am often asked to evaluate web-based software at my job, and I would immediately vault an application written in Rails over one written in PHP. Without even trying the application, I know the Rails app is recent, still in active development, and won't be a spaghetti-code nightmare to maintain.
posted by nev at 2:59 PM on December 4, 2005


The Computer Language Shootout Benchmarks shows that Ruby (without rails) is a bit slower than PHP, and Rails will only make it slower.

For PHP at least you can use Zend Accelerator which improves peformance, and I don't know if such a thing is available for Ruby. Then again, programmer time is more valuable than machine time.

After a quick glance on Ruby/Ruby on Rails, I decided that's it's not worth it for me.
posted by Sharcho at 3:09 PM on December 4, 2005


Should I switch from PHP to Ruby?

I'm currently playing around with Ruby, coming from a pro PHP background. More because I'm interested in languages, than because I'm seriously looking to replace PHP at this point (but I'm not negating the possibility that I may fall in love with Ruby along the way).

The Rails framework is very interesting from a web development point of view, and eases certain aspects of the web development process. That said, if you're reasonably competent in PHP, Rails doesn't offer anything that you can't or haven't achieved in PHP, and as others have mentioned again and again, Rails != Ruby, just as Smarty != PHP (although I'm not trying to imply a correlation between Rails and Smarty).

So far I'm enjoying playing around with Ruby, and with Rails. I haven't had the 'Bazang!' moment yet, but it might come from projects like RubyScript2Exe.

I'm still a little disappointed that there's no official support for a MySQL driver (which is not to say they don't exist, but WinXP users are going to be frustrated that the only MySQL API module for Ruby hasn't been packaged for WinXP, meaning they have to rely on the ruby-mysql package, which is written in Ruby and which probably suffers speed-wise against the C++ version).
posted by planetthoughtful at 3:20 PM on December 4, 2005


Just wanted to post to let the person asking the question know that the above is a pile of FUD.

I have no vested interest in the success or failure of either PHP or Ruby, so it cannot be FUD by the usual definition.

I actually installed and tried Rails. I didn't like it, and found that it had a pretty steep learning curve to boot. Sorry if that offends you.
posted by trevyn at 4:54 PM on December 4, 2005


Best answer: As far as libraries are concerned, Ruby's behind on quantity, but in my experience generally ahead on quality, although it depends on exactly what you want to do. As per your examples, PDF::Writer seems nice, and I've used ruby-gd in a production system for several years. Word and Excel can be controlled on Win32 systems via WIN32OLE. If a suitable extension/library doesn't exist, you can always call PHP from Ruby, or vice versa. There's a wide range of web application frameworks to play with, not just Rails (Iowa and Nitro to name a couple), but you don't have to use them any more than you need to use a framework with PHP.

"spaghetti code"-wise, well, you can write pretty shocking code in any language, and Ruby certainly won't stop you doing so, but what it will do is allow you to be more creative in how you structure things, with plenty of good examples to learn from and interface with; to me, PHP feels highly constraining and ad-hoc by comparison. Ruby flows.

Performance wise, Ruby's not the fastest, but in my practical experience it's easily on par with PHP, and Ruby 1.9/2.0 are only going to get faster. Part of this is from coding style; a Ruby FastCGI daemon can pay its app-startup cost once and serve multiple requests without having to do a lot of setup repeatedly -- PHP's design involves throwing away all that each request, so you end up recreating objects and reloading your apps config files every hit, even with a bytecode cache.

Learning Ruby will do you good as a programmer; same with any other language really, but Ruby's sufficiently different from PHP to give you a nice new outlook without being so different you get completely lost. YMMV.
posted by Freaky at 5:20 PM on December 4, 2005


Yeah... why not learn it? It can only serve to make you more marketable and learning new techniques can only benefit you in the future.

'Course, if you only had to learn one, I'd say PHP, given the number of jobs and whantot in the field right now...
posted by ph00dz at 6:30 PM on December 4, 2005


So far I'm enjoying playing around with Ruby, and with Rails. I haven't had the 'Bazang!' moment yet, but it might come from projects like RubyScript2Exe.

At a glance, PHP-GTK seems to offer the PHP equivalent of the RubyScript2Exe experience, although, ironically, it doesn't seem as mature.

Meanwhile, not for nothing, but Freaky's claims about PHP's resource expenditures for each request might be a little off-base, depending on how you implement PHP. You can use a CGI implementation or a commandline implementation, the latter being significantly faster.

However, PHP-CGI can also take advantage of FastCGI, although I have no experience to dictate if PHP-CGI over FastCGI is as speedy as Ruby over FastCGI. I think if you're doing anything significant with your database, your bottlenecks will be on that end, anyway.
posted by disillusioned at 6:36 PM on December 4, 2005


I know the Rails app is recent, still in active development, and won't be a spaghetti-code nightmare to maintain

Couldn't you also say PHP is mature, still in active development (with PHP 5 just released this year), and easy to maintain if programmed properly?
posted by kirkaracha at 8:10 PM on December 4, 2005


For the sake of completeness, Python should be mentioned. People that use Python like it- a LOT. There have been two prominent attempts in the Python community to respond to Ruby on Rails: Django and Turbogears. I've heard good things about both, and have used Turbogears myself (its not perfect, but very good). And by going with Python, you're choosing a language that has a much larger community that Ruby, but is still much better designed than PHP. In my experience, Python has a much larger range of libraries available to it than either PHP or Ruby.
posted by gsteff at 8:38 PM on December 4, 2005


I actually installed and tried Rails. I didn't like it, and found that it had a pretty steep learning curve to boot.

Right, but you're comparing the feature set of a Ruby framework to the feature set of PHP the language.

My opinion is that Ruby or Python are good languages to learn since they provide very different ways of doing things. Whether they are better ways is left to personal opinion. My feeling is nothing but good can come from seeing different approaches.
posted by yerfatma at 7:25 AM on December 5, 2005


Couldn't you also say PHP is mature, still in active development (with PHP 5 just released this year), and easy to maintain if programmed properly?

Sure, those are all valid considerations. But lately I've started to feel that "maturity" in a web application framework is a liability rather than a bonus. ColdFusion and ASP/VB-Script are mature, too.

Rails and the Python projects that gsteff mentions are great counterexamples of lightweight, MVC-centric frameworks that are attractive precisely because there's so little to them and they're so easy to read.

(And I'm already convinced that Turbogears 1.0 will actually be perfect.)
posted by nev at 5:58 PM on December 5, 2005


Response by poster: gem.rubyforge.org currently lists 587 unique gems for download and install. *shrug* If you can't find what you need, are you thinking that your requirements are really all that unique?

Thanks! This is extremely useful. Are my requirements all that unique? Probably not, but I just didn't want to get halfway through writing an application and discover that I can't do something basic. Years ago it happened to me with ASP (the way that ASP handled included files drove me bananas), and I just didn't want to get myself into a situation where I couldn't, I don't know- like, write text into a file or something. And I can so easily imagine posting my pathetic little cries for help on a Ruby message board, and someone replying, "Of course you can't write text into a file. Why would you want to do that? If you wanted to do that, you should have stuck with PHP." Which was more or less my experience with ASP and my little include problems.

Anyway, I was just sort of reaching out to anyone who had made the switch from PHP to Ruby and was going to say to me, "don't do it- you can't even do (whatever)." But I haven't seen that yet, so that's good.

I don't know a lot of these things, but I recently listened to two ruby-loving friends bitch about how Ruby on Rails is a lousy piece of software that is essentially the opposite of straight-up ruby.

I can see the value in Rails for people who are setting up many small websites- It gets you over that first little hump of getting things going very quickly. But I'm starting to wonder whether it'll be all that useful in long-term development on a single project. I suppose it promotes consistency, but I worry about, for example, how upgrades will be handled- if I spend a year pounding away on this project, will I then be able to just drop in the latest version of Rails, with all of it's improvements and ajax goodies? Or will I have departed from the Rails framework to the point where the Rails framework no longer meshes with my application? I tend to think the latter would be the case.

Do you want to be a better programmer? Do you want to extend your skill set outside of just web programming? Those are both good reasons to learn a standalone language like Ruby.

Yeah... why not learn it? It can only serve to make you more marketable and learning new techniques can only benefit you in the future.


I would love to learn Ruby. I plan to. I'm most of the way through "Agile Web Development with Rails", which has been an excellent tutorial. I LOVED Why's (Poignant) Guide to Ruby. It's not a question of whether to learn it, it's a question of whether to use it for this web app that (for reasons of foolish optimism) I hope to be working very hard on for some time to come.

I keep hearing things like, "I'm 5 times more productive" with Ruby on Rails than I was with PHP." And I see that Tim O'Reilly has become a Ruby on Rails evangelist. And I read things like, "Ruby will teach you to express your ideas through a computer. You will be writing stories for a machine." And I can't help it, Ruby just seems sexy. But really, PHP has never let me down yet.

For the sake of completeness, Python should be mentioned. People that use Python like it- a LOT.

Dammit, I was already indecisive. I was hoping to narrow down my choices. The problem with me is that if I start considering third or fourth options, my brain will start thinking along the lines of, well, for that matter, why don't you just write that damn novel you're always thinking about? Or learn the guitar?

Anyway, thanks again to everyone for your feedback.
posted by jay.jansheski at 6:06 PM on December 5, 2005


Response by poster: Boy, that Turbogears site is pretty. Maybe I should consider Python.
posted by jay.jansheski at 6:10 PM on December 5, 2005


Response by poster: I also keep thinking that maybe the best thing to come from Ruby on Rails is the idea of a framework. Or at least, it brought the idea of a framework into the mainstream. Maybe it doesn't really matter what language you use, as long as you don't get yourself into a situation where you're the only one using it, or where you're having to pay lots of money in licensing fees to use it.

Alternately, this decision could be the one that determines my fate, either throwing my life into chaos and misery or bringing me long term peace and fulfillment. Actually, I've been using PHP for a while, and I've certainly had my share of chaos and misery. Maybe I should choose whatever is the opposite of PHP.
posted by jay.jansheski at 6:32 PM on December 5, 2005


I also keep thinking that maybe the best thing to come from Ruby on Rails is the idea of a framework. Or at least, it brought the idea of a framework into the mainstream.

Java has lots and lots of frameworks, but none of them are, shall we say, agile (it's Java, after all). I do agree that a lot of the principles of Rails are driving projects like Turbogears: don't write any SQL, URLs map directly onto methods, configure in code and not in config files. Coding this way can feel truly effortless.
posted by nev at 6:53 PM on December 5, 2005


Response by poster: Update: I switched to Rails. I'm very happy I did. I'm sure I'll still be using PHP where it's appropriate, but for this particular project I'm working on, I'm glad I made the jump.

One of my big concerns was hosting, but I found a great solution for that at rimuhosting.com. You can set up the server by following this excellent tutorial: The perfect Rails/Debian/Lighttpd Stack.

I would also highly recommend these books:

Agile Web Development with Rails : A Pragmatic Guide

and

Programming Ruby: The Pragmatic Programmers' Guide, Second Edition.
posted by jay.jansheski at 7:04 AM on April 22, 2006


« Older Out-of-the-box Web2.0/Google Maps?   |   Slow Mac connection. Newer »
This thread is closed to new comments.