File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Ruby and the fly likes Why should I choose Ruby? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Languages » Ruby
Bookmark "Why should I choose Ruby?" Watch "Why should I choose Ruby?" New topic

Why should I choose Ruby?

Ivan Wang

Joined: Oct 14, 2007
Posts: 3
Well,I've learned and used Java for about 2 years.And now Ruby is very popular.Many people say Ruby on Rails can quickly develop a web application.
But Ruby is very different from Java.And Groovy on Grails can also quickly develop a web application.
So I want to know ,Should I choose Ruby?Dose it better than GOG?
Peter Johnson

Joined: May 14, 2008
Posts: 5852

To add to what Ivan has asked, if I am already proficient in Java, and Groovy enables me to retain the Java skills that I have already learned, why would I want to learn Ruby? What are the unique features of Ruby that would make it worth learning?

In addition, each language tends to require a certain way of thinking about a problem. One aspect of learning a new language is retraining oneself to think in that way. This is usually a good thing because it expands the ways that one can look at problems, thus make one a better developer or designer. What are the unique ways about thinking in Ruby that would add to a developer's body of knowledge?

JBoss In Action
Michael Sullivan
Ranch Hand

Joined: Dec 26, 2003
Posts: 235
Think Different. Some examples:

Try/Rescue in place of if/then/else
||= (evaluates the right hand side if the left hand side is nil)
Ducktyping and Metaprogramming
Everything is an object. 1 is an object. So is false. So is nil.

DSL (domain specific languages) are big in dynamic languages like Ruby.
The Rails framework makes for an interesting comparison against Java frameworks like Struts/Struts2/JSF/Tapestry/etc
Memoize and MemeCaching
Rack, and Metal
Modules and Mixins

Default method parameters, hashes as parameters, variable length argument lists
code blocks as parameters, code blocks passed to the method

Assaf Arkin

Joined: Feb 09, 2009
Posts: 16
Meta-programming is big. You don't realize how much time you spend maintaining unnecessary code until you go down the path of meta-programming. You're letting the code do more work for you.

Behavior Driven-Development. In some languages, writing tests is painful, feels like punishment. Ruby makes testing so much easier, so it's easier to develop applications tests first, easier to refactor the code, since you have tests that can tell you when something goes wrong. It's easier to keep the code clean and without smell. And the next step, writing the design of the application, the behavior, as part of the application itself.

Duck typing, in fact the whole approach to OO, means my Ruby code has very shallow class hierarchy, and less classes than the Java equivalent, which by itself gets rid of a lot of complexity.

Scripting. I'm surprised every time I see people clicking through menus, upload wizards, admin panels to deploy a new version of the application. Can't you just automate it with a simple script? Not all scripting languages are actually good for automating your workload, though. You can do a lot of that with Ruby, not so much with JavaScript.
Ivan Wang

Joined: Oct 14, 2007
Posts: 3
Actually,Ruby isn't exciting me and Groovy isn't too.But when I see Grails,I'm very exciting.
It makes me do less to do more things.Now I'm learning Grails.So I want to know does Rails has something better than Grails?Not Ruby.
Grails use Spring and Hibernate,which has been very popular!And Grails can use the web server which Java uses.

I am sorry .English is not my mother language.So....
Paul Nanouk

Joined: Jun 11, 2004
Posts: 1

Try this in other psuedo-object oriented languages/scripting: --> produces {3}

Ruby treats everything as a true object even integer literals.
Teaching beginning students and adults is made so much easier, IMHO.

Amit Ghorpade

Joined: Jun 06, 2007
Posts: 2851

"Nanouk Nanouk " please see your private messages for an administrative PM.

|Asking Good Questions|
Assaf Arkin

Joined: Feb 09, 2009
Posts: 16
Grails was originally called "Groovy on Rails", and from what I understand copied all the good ideas behind Rails to the Groovy language. I think it did a good job copying Rails, but also Rails is still far ahead.

chris webster

Joined: Mar 01, 2009
Posts: 2289

I can really recommend Grails. I'm no Java expert, but I've been working occasionally with Java for several years, and I've always found J2EE a real pain (too much XML Configuration Hell for one thing). Grails takes the pain away and it's great.

Like Ruby, it's based on "convention over configuration" i.e. if you work with the conventions of Grails (naming, file locations, design patterns etc), then it is incredibly easy to get a real 3-tier J2EE database app running and deployed onto e.g. Tomcat.

But one big advantage over Ruby/Rails is the easy and complete integration with Java out of the box. Grails includes masses of standard enterprise Java libraries like Spring and Hibernate (partly because it's actually built on top of those libraries). But it's also easy to mix in your own Java code and other libraries as you need them. It is also very flexible e.g. you can opt out of the conventions if you want, set up your own URL mappings (for REST), use different object-relational mapping tools, map your objects to legacy DB tables, or whatever you want. So you get all the power of enterprise Java, plus great flexibility, but none of the pain.

If anybody wants to try it out, I suggest downloading the free PDF book Getting Started With Grails by Jason Rudolph, which will do exactly what it says: you'll have your first Grails app running in minutes, seriously. There's also a video presentation by the same guy to give you a quick intro to what Grails is about.

Then you could progress to the Mastering Grails series by Scott Davis on IBM Developer Works, which includes some extra ideas like Google Maps mash-ups, for example, as well as looking at Grails support for things like unit testing (JUnit is built into Grails of course).

Then if you want to get serious about Grails, get The Definitive Guide to Grails (2nd Edition) by Graeme Rocher and Jeff Brown.

And remember, Grails actually makes enterprise Java fun, so give it a try!

No more Blub for me, thank you, Vicar.
Ivan Wang

Joined: Oct 14, 2007
Posts: 3
Thank you very much.
I'll learn grails first
I agree. Here's the link:
subject: Why should I choose Ruby?
It's not a secret anymore!