tags:

views:

384

answers:

9

Hi! I'm an intermediate PHP web developer and I'm currently working on a website project. Being totally new to the whole business I've programmed my server side part with PHP.

Now I've read everybody's using "Ruby on Rails" and it makes other languages obsolete and all that. Is that really true? Is there any value to transforming my entire website infrastructure to Ruby? It really seems like a grueling task, besides learning a whole new language, I wanted to ask what you think about this.

Thanks a lot for answering.

+8  A: 

PHP is widely used in web applications, but if you want to use Ruby on Rails, or are looking for a programming language that is designed for general cases, Ruby is certainly worth a look. Commonalities Just like in PHP Ruby ...

  • Ruby is dynamically typed, like in PHP, so you do not need to worry about having to declare variables.
  • There are classes, and you can control access to them like in PHP 5 (public, protected and private)
  • Some variables begin with $, just like in PHP (but not all).
  • There's eval, too.
  • You can use string interpolating. Instead of doing "is a $foo $bar", you can do "#{foo} is a #{bar}"-like in PHP, this does not apply for single quoted strings.
  • There's heredocs
  • Ruby has exceptions, like PHP 5
  • There's a fairly large standard library
  • Arrays and hashes work like expected, if you exchange array () for (and): array ( 'a' => 'b') becomes ( 'a' => 'b').
  • True and false behave like in PHP, but zero is denoted by nil

Differences Unlike PHP has Ruby ...

  • There's strong typing. You'll need to call to_s, to_i, etc. to convert between strings, integers and so on, instead of relying on the language to do it
  • Strings, numbers, arrays, hashes, etc. are objects. Instead of calling abs (-1), it's 1.abs
  • Parenthesis are optional in method calls, except to clarify which parametres go to which method calls
  • Instead of naming conditions, like underscores, the standard library and extensions are organized in modules and classes
  • Reflection is an inherent capatibility of objects, you do not need to use Reflection classes like in PHP 5
  • Variables are references.
  • There's no abstract classes or interfaces
  • Hashes and arrays are not interchangeable
  • False deliver only false and nil: 0, array (), and "result in conditions true.
  • Almost everything is a method call, even raise (throw in PHP).
streetparade
Ruby's string interpolation uses brackets not parentheses: `#{foo}` not `#(foo)`.
Telemachus
that should be "braces not parentheses" -- {braces}, [brackets], (parentheses)
glenn jackman
@Glenn: yup, noted. @Streetparade: I'm editing the post itself.
Telemachus
@Telemachus ok thanks for the edit
streetparade
+26  A: 

I have a very low personal opinion of PHP and a rather good one of Ruby. But even so, I think that taking a finished, working site and re-writing it just to be "hip" is an exercise in unnecessary masochism.

Beside the pain, one practical disadvantage of doing this would be that you'll be tempted to keep much of the old design's structure, and thus would not be producing "idiomatic" RoR.

I think it would be a good idea to write your next site in Ruby, from scratch, and with use and learning of all the cool RoR features. This will be more fun, more productive and probably result in a better product.

Until you get started on that, you could perhaps write some "play" programs in Ruby to become familiar with the syntax, the features, etc. This will allow you to later concentrate on features of Rails without having to learn most of Ruby at the same time. I did this, but it hurt my head :)

Carl Smotricz
+2  A: 

Short answer: No.

Long answer: Every change comes with the cost. If you have written a lot of code in PHP already, you probably have to rewrite them as there is no mechanical translator between PHP and Ruby. Also you have to teach yourself Ruby, so actual cost is much bigger.

While both Ruby and RoR is a decent language and framework so worth looking at it, rewriting everything in them is just a stupid idea. So does the assertion "RoR will make other languages obsolete".

Kang Seonghoon
+1  A: 

What do you want the site to do that you can't do on the foundation already in place? If the answer is "Nothing", then there's no need to do a rewrite.

If you want to learn RoR for your own education, you might be better served by starting with toy projects in which failure, delays, rework, etc. have no significant consequence.

joel.neely
+2  A: 

This isn't quite an answer to the question but I think it's important for everyone considering the switch between PHP and Ruby. Rails is particularly built for creating applications, be they CMSs or custom airline apps. So do not get into Rails thinking that it's going to feel like a CMS or anything in particular at all.

If you're still building traditional content-based websites you would probably do better sticking to Drupal in my honest opinion.

I've been struggling with this fact for a long time and I used to hate making content-based websites in Rails because it was a total pain, but now I realize that the reason for this is that Rails just isn't built for that. It is built to become a CMS, not be a CMS.

So, I hope that gives you some more questions. :P Kind of mean I guess to make the switch even more confusing for you.

Chuck Vose
+8  A: 

Remember, Ruby is the language. Rails is a framework. Are you using a framework currently? If not, you might look into a PHP framework like Cake, CodeIgniter or Kohana and see if a package like that would be useful to you. Switching languages AND to a framework at the same time is a huge shift that may be more trouble than it's worth for an already existing application.

Alex JL
A: 

I need to ask you why? Besides you heard about "everybody uses rails", why are you considering move to Ruby? Your experience with php was bad? Wich framework are you currently using with php?

Anyway Rails is a framework.

My opinion: try php frameworks. You are developing in php, go on with php. You still can test Ruby+Rails to compare. Then make a choice.

mRt
A: 

You might want to look at Sinatra or Ramaze using one of the template engines like erubis or HAML, rather than jumping into Rails. I found Rails to be very insistent that I do things its way. I thought its learning curve was tough but that was partially because I caught it immediately after a big Rails upgrade so the docs and books hadn't caught up.

I used ActiveRecord in several projects and thought it was OK, but prefer Sequel over it when talking to a database. Using erb-type templates are OK, but I like HAML more. Ramaze, being agnostic, doesn't seem to care which I use. That agnostic flexibility might work a lot better for you if you wrote your PHP site in a MVC style. That will help get you familiar with Ruby without being confused by Rail-isms.

Greg
A: 

The assumption that everyone is switching to rails is not true. Go to any job site and type in ruby on rails in the search. I promise you it will be far less than PHP or ASP.Net. Where I live, it rarely shows up on the search at all.

If the site is done in PHP, I would leave it there. There is still far more support for PHP.

Start simple with RoR to get a good grasp before taking on a huge project in a new language/framework. It might make you resent it before you really get a chance to understand it. I just picked up a RoR book to see what its all about, but I plan to keep PHP as my forte.

Chad