aspose file tools*
The moose likes Ruby and the fly likes comparison of PHP with Ruby Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Languages » Ruby
Bookmark "comparison of PHP with Ruby" Watch "comparison of PHP with Ruby" New topic
Author

comparison of PHP with Ruby

Suganya Ram
Greenhorn

Joined: Jun 12, 2008
Posts: 18
(string)Time()
This is the function used in PHP.

What is the equalent of this function in Ruby?


SuganyaRam
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14104
    
  16

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:


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Rusty Shackleford
Ranch Hand

Joined: Jan 03, 2006
Posts: 490
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.


"Computer science is no more about computers than astronomy is about telescopes" - Edsger Dijkstra
Paul Michael
Ranch Hand

Joined: Jul 02, 2001
Posts: 697
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.


SCJP 1.2 (89%), SCWCD 1.3 (94%), IBM 486 (90%), SCJA Beta (96%), SCEA (91% / 77%), SCEA 5 P1 (77%), SCBCD 5 (85%)
David Berube
author
Greenhorn

Joined: Jun 18, 2007
Posts: 26
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

Joined: Jul 02, 2001
Posts: 697
Thanks David!
Nick Plante
author
Greenhorn

Joined: Sep 01, 2008
Posts: 13
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
Greenhorn

Joined: Jun 18, 2007
Posts: 26
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 ]
Matt Price
Greenhorn

Joined: Feb 02, 2009
Posts: 18
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.
Assaf Arkin
Author
Greenhorn

Joined: Feb 09, 2009
Posts: 16
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.
sanjay ramaswamy
Greenhorn

Joined: Feb 11, 2009
Posts: 29
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 ???


"People who are unable to motivate themselves must be content with mediocrity , no matter how impressive their other talents " -Andrew Carnegie
santoshkumar savadatti
Ranch Hand

Joined: Apr 27, 2010
Posts: 95
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

Joined: Apr 27, 2010
Posts: 95
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: comparison of PHP with Ruby