tags:

views:

668

answers:

6

I need a quick overview to figure out if it's worth switching from PHP to ruby. Please list some differences you know. I'm just talking about PHP and Ruby, not Ruby on Rails (that would be a bad comparison).

+3  A: 

Read this article, you might find something useful:

http://www.cmswire.com/cms/industry-news/php-vs-java-vs-ruby-000887.php

karim79
Scaling is an architectural issue, not a language issue.
jshen
+4  A: 

It's a highly subjective question to ask. Having worked with both, I can give you my observations.

Overall I would say that PHP is a more stable and mature environment than Ruby is. There are more available libraries, and they have had time to stabilise. It's also a lot easier to configure and deploy, because there are generally working packages for your platform, and because you don't have to make a lot of choices upfront.

As a language, both are similar in that they are easy to start using, but hard to master completely. PHP is a bit more traditional, which may make it easier if you already know Java/C/etc. On the other hand, PHP is internally much more inconsistent than Ruby. I think it is safe to say that Ruby is aesthetically better off than PHP; It's in many ways a very elegant language. You can't really say that about PHP. On the other hand, PHP is much more by face-value. In Ruby you can - and people often do - write some truly incomprehensible code.

troelskn
Downvote removed, this is not downvote worthy.
karim79
"There are more available libraries [for php]"Ruby has a lot more if you count the java libraries that jruby can use. I think jruby is a game changer in this regard which vaults ruby to a new level.
jshen
I'd argue that JRuby is a different platform from Ruby. Relying on Java backend doesn't make much sense unless your existing platform is already Java, in which case your Ruby code merely becomes a scripting frontend for Java. Curiously enough, there actually is a fairly stable Java-bridge for PHP (As well as a COM bridge).
troelskn
Jruby makes a lot of sense even for greenfield projects. It's faster than native ruby. It has real threading. The garbage collector is leaps and bounds better than native ruby. And, you can speed up bottlenecks by writing a few small pieces in java. Jruby gives ruby some serious advantages.
jshen
OK about making sense for greenfield projects, but I'll still maintain that JRuby is a different platform from Ruby. Ruby exists in the *nix ecosystem, like other scripting languages, with the benefits and drawbacks that comes with that. JRuby exists in the ecosystem of Java. That makes them quite different, even if they look the same on the surface. In Ruby, you can speed up bottlenecks by writing a few small pieces in C.
troelskn
I don't see the significance of the distinction you Are making. Ruby code is ruby code and it runs the same on jruby as it does on MRI ruby. A great example is rails. I can create a rails app and run it in jruby or MRI ruby, it runs exactly the same. My point about using java for speedups is that it's a lot easier than using c.
jshen
Yes, but if you use an external library, you may suddenly find yourself depending on the platform. For example, if you use a gem that has bindings to a binary library, it may only work in Ruby. Or if you have used a Java library, it will only work in in JRuby. As for easy, that depends. If you have an existing library with C-header files available, it may be fairly trivial to write C-bindings to it, using FFI.
troelskn
I think my core point stands. Jruby gives ruby advantages that php doesn't have
jshen
PHP has that same ability. It's just rarely used, because there are so many libraries available as native extension for php. See: http://www.php.net/manual/en/book.java.php and http://www.php.net/manual/en/book.com.php
troelskn
These are not the same thing.
jshen
A: 

My experience having moved from a java / PHP background to Ruby (using Rails) I found Ruby almost incomprehensible. I definitely believe it's more powerful, but many of the Ruby frameworks work concepts such as metaprogramming and closures (blocks, procs, lambdas etc). Learning PHP from a Java / C++ / C background was a lot easier than learning Ruby subsequently.

It's worth it, but expect exasperation initially.

Julian
Going from any language you're very experienced with to a different one will be exasperating. Your mind unconsciously molds itself to fit the language you use most often, so a new language — no matter how bad or good — will feel very weird and disorienting. This is also why it's very worthwhile: It helps to teach you what's actually possible beyond the "obvious" things in the language you already know. This is one of the big reasons people say learning functional programming is such a good exercise.
Chuck
When I moved from Java to Ruby 3 years ago, I spent about 6 months writing Java code, except in Ruby. :) It was a worthwhile transition though as it opened my mind beyond C-style languages.
Sarah Mei
+4  A: 

Ruby has closures and powerful meta programming facilities. PHP doesn't. Jruby also gives you a lot of things you don't have in php. For example, you can use any java library directly in jruby, and you can deploy ruby (rails as well) on any typical java setup.

Also, check out heroku for an awesome hosting option for ruby.

jshen
A: 

I advice you not to switch to Ruby. If you want to leave PHP and start programming only in Ruby, than it's not a good idea. For now, it is worth to write in PHP, beacause many web (and not only) applications are written using PHP, while far less in Ruby. I'm not saying that it is not worth to learn it, because Ruby is very powerful and gives lot of joy.

The main difference: that, what takes you ie 10 lines of code in PHP, in Ruby would take 2. But it's also this times slower, beceause that what makes this language so beautiful makes it also slower.

Of cource it depends on what do you want to do with knowledge of these languages.

@jshen PHP since 5.3 has closures, too.

shazarre
Technically 5.3 is still not released.
jmucchiello
Ruby is not that much slower than PHP. PHP is a bit faster than Ruby, and Java and Haskell are faster than PHP, but you didn't go all the way and recommend one of the fastest languages — because language speed isn't the limiting factor on most Web apps. So it seems a bit unfair to penalize only Ruby for something that you presumably don't feel is that important.
Chuck
And so what? We are talking about PHP and Ruby here.
shazarre
@jmucchiello - Yes, I know, but it's the direction which PHP takes, so I mentioned it as a possible feature.
shazarre
+1  A: 

One big point that many of the other posters have neglected to mention is that deploying PHP is dead simple. Most webhosts provide PHP by default, which means that deployment is a simple matter of copying some files to a server. Ruby, by contrast, would require you to either set up some sort of application server (the Rails way) or set up CGI (does anyone do that anymore?).

Another consideration, assuming you're doing web development, is that PHP is 'web native' - it expects to be dealing with HTTP requests & responses. In pretty much every other language, you need to manually set this up.

Personally, I don't care much for the PHP language, in the abstract, but the language is a good fit for the web development niche & mod_php is really good at what it does (as well as being nearly ubiquitous).

Sean McSomething
With Passenger, you can just stick your Ruby app somewhere on your server and make a one-line change to your Apache config and you're good to go. I wouldn't really classify that as hard.
Chuck
took me 3 days to set up the web environment with ruby/rails, compared to 30 minutes with php the first time. the problem is always figuring out how to do it, not doing it.
never_had_a_name