my dog learned polymorphism
The moose likes Ruby and the fly likes Common obstacles for newcomers to Ruby? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Languages » Ruby
Bookmark "Common obstacles for newcomers to Ruby?" Watch "Common obstacles for newcomers to Ruby?" New topic

Common obstacles for newcomers to Ruby?

Michael Sullivan
Ranch Hand

Joined: Dec 26, 2003
Posts: 235
Hello Peter,

Have you found any common obstacles that newcomers to Ruby routinely face?
In your opinion, are there any language features that seem more difficult to grasp?
Do you find certain patterns that developers with prior OO experience exhibit when first tackling Ruby?

Peter Cooper

Joined: Jul 17, 2009
Posts: 25
When I've taught developers who have come from languages like PHP and Cold Fusion, there has been a confusion over the flexibility of the syntax in many cases. One key example is stuff like:

puts "x is even" if x % 2 == 0

Versus the more traditional (but lengthier and less idiomatic):

if x % 2 == 0
puts "x is even"

Another stumbling block is the "pure" object oriented nature of Ruby. A lot of developers seem to be used to arbitrarily mixing procedural ideas with object oriented ones. In Ruby you can do this but in reality you'd try to avoid it as much as possible. Even in a similarly dynamic language like Python, there's a heavy reliance on functions.. such as using len(str) rather than str.length, or similar.

I find that most of the stumbling blocks come from assuming Ruby is as inconsistent or "mixed" as other languages, when really the standard is to try and keep things as simple as possible. Ruby tends to assume it's easier to learn operators than structural syntax, so while you won't see so much "structural" definitions or endless initiators as in Java, you'll instead see operators or shortcuts.

Consider this Java-ish example (I know this isn't Java, but it's a similar style):

arr =

Versus the more Ruby-esque:

arr = []
arr << 10
arr << 20

You *can* write Ruby in the former, more Java-esque way, but you'd tend to write more idiomatically as in the second example.

Regarding certain patterns that existing OO developers find tough, I'd say that from certain languages (such as Java), the lack of multiple inheritance can be "interesting" to start with The existence of modules that are then mixed in to classes can also provide a little bit of a learning curve, but it's mostly about changing expectations than learning anything hard.

Author of Beginning Ruby (Apress):
Editor of Ruby Inside and RubyFlow
Michael Sullivan
Ranch Hand

Joined: Dec 26, 2003
Posts: 235
Interesting. I've found many of my Java peers to be deeply offended at "multiple ways" to do the same thing. I've found passing blocks/closures to be a new challenge simply because I haven't done a lot of it.

I found this code: arr << 20 to read well after using Ruby a bit, though from the outside it looks "Perlish" to my peers.

Thanks for your comments!
I agree. Here's the link:
subject: Common obstacles for newcomers to Ruby?
It's not a secret anymore!