• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

comparison of PHP with Ruby

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
(string)Time()
This is the function used in PHP.

What is the equalent of this function in Ruby?
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't know much about PHP, so I don't know what Time() does, but I guess it gets the current system date and time.

In Ruby, you do that by creating a new Time object. To print the current date and time, for example:
 
Ranch Hand
Posts: 490
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Time.now will give you the current time and date.

If you use the activesupport gem you can do awesome stuff like this in ruby: 10.days.ago or 5.minutes.from_now or 22.weeks.from_now these are all methods, in ruby the () is usually optional

>> Time.now
=> Tue Jul 08 01:06:00 -0700 2008

>> 10.days.ago
=> Sat Jun 28 01:06:04 -0700 2008

>> 5.minutes.from_now
=> Tue Jul 08 01:11:09 -0700 2008

>> 22.weeks.from_now
=> Tue Dec 09 01:06:11 -0800 2008

Ruby is an elegant language.
 
Ranch Hand
Posts: 697
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To our guest authors:

There have been TONS of sites/posts saying Rails is better than PHP (+PHP framework here). There are also some of them which says the exact opposite.

Given the varying opinions, where do you think is it more suited to use PHP/PHP+Framework over Ruby/Ruby+Rails and vice versa?

Thanks.

PS I don't intend to start a fight. I'm just interested in the authors' opinion on the topic.
 
author
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
PHP scripts are easier to deploy then Rails apps, at least at the moment; for small stuff - "contact us" forms - I wouldn't bother creating a Rails application. For larger apps, in my opinion, you'll have quicker development and easier maintainability by switching to Ruby on Rails.

That being said, realize that Rails is a *very* opinionated environment - Rails wants you to use artificial primary keys, validate in your models (vs database), singular models and plural tables, etc. Working within Rails constraints can be a joy; bumping up against them all the time is painful. (This is deliberate - a more flexible system would require more typing and more configuration. The assumptions Rails make speeds up your development significantly.)

Of course, note that Ruby itself isn't opinionated; there are a number of promising web frameworks which differ from Rails and different approaches. (Mack, merb, etc.)

Take it easy,

David Berube
 
Paul Michael
Ranch Hand
Posts: 697
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks David!
 
author
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I agree that Rails apps still aren't as easy to deploy as simple single-page PHP scripts. But that's what happens when you've got a whole framework to deploy, right? I would argue that these days, a Rails-based application isn't much more difficult to deploy than a comparative PHP framework-based application, though (like CakePHP, Symfony, etc)...

The Passenger Apache Module has made it pretty easy to get started with Rails on the deployment side of things. Check it out if you're unfamiliar with it. Simply gem install passenger, then run the command to compile and install the module and edit your vhost directive. Things get even easier once you learn and start using Capistrano as part of your deployment routine.
 
David Berube
author
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
IMHO, it's easier to deploy a Rails app than a CakePHP app. Recent builds may have improved, but last time I had to deploy a CakePHP app significant and nonobvious mod_rewrite'age had to happen before it would work. (It worked fine on my test server, of course.)

Going along with what Nick said, for any non trivial application, you're going to eventually have to deal with automating deployments, db migration, scalability to multiple app servers, etc, and Capistrano is *great* at that.

Take it easy,

David Berube
[ September 04, 2008: Message edited by: David Berube ]
 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
now = Time.now.to_s

would be the simplest way. First you get the time, then you call its to_s method which converts it to a string. Ruby doesn't have casting, so you have to use methods.
 
Author
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I was working on a PHP library for extracting microformats from HTML, when a friend introduced me to Ruby. As an exercise, I decided to rewrite it Ruby, and fell in love and never looked back.

The applications I work on mix front-end and back-end stuff, and on the back-end I think Ruby is a league away from PHP. On the front-end side, for larger applications I'll use Rails, I never used CakePHP so I can't tell if it's better or not. For smaller stuff, I'm going to use a smaller framework like Sinatra, or no framework at all, and it will be either Ruby or PHP, most likely PHP: my site it a WordPress blog, so it's just easier to do everything PHP.
 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rusty Shackleford wrote:Time.now will give you the current time and date.

If you use the activesupport gem you can do awesome stuff like this in ruby: 10.days.ago or 5.minutes.from_now or 22.weeks.from_now these are all methods, in ruby the () is usually optional

>> Time.now
=> Tue Jul 08 01:06:00 -0700 2008

>> 10.days.ago
=> Sat Jun 28 01:06:04 -0700 2008

>> 5.minutes.from_now
=> Tue Jul 08 01:11:09 -0700 2008

>> 22.weeks.from_now
=> Tue Dec 09 01:06:11 -0800 2008

Ruby is an elegant language.



How do you get the active support gem . By the way a gem is a package right? so how can i find such packages or have a look at a list of packages ???
 
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

How do you get the active support gem . By the way a gem is a package right? so how can i find such packages or have a look at a list of packages ???



gem list
That will show a list of gems you have installed.
 
santoshkumar savadatti
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I worked a bit on Rails and a bit on cakePHP.
There may be many underlying differences.But, what struck me was, when working with Rails, the framework is "Alive".That is, the framework is talking to you.When working with cakephp, you extend some class and so on.But, the framework isn't interacting.
For e.g., in Rails, when we say Rails G controller <controller name>, a file is automatically created in the appropriate position.Where as, when working with PHP frameworks, you have to manually create those files in their locations.
While it is just a small step, it is very convenient and a pleasure.The simplicity of Rails makes you want to create more things.....just to use the lovely framework.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic