This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Languages » Ruby
Bookmark "Common obstacles for newcomers to Ruby?" Watch "Common obstacles for newcomers to Ruby?" New topic
Author

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?

Thanks!
Peter Cooper
Author
Greenhorn

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"
end

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 = Array.new
arr.push(10)
arr.push(20)

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): http://bit.ly/t31ag
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: http://aspose.com/file-tools
 
subject: Common obstacles for newcomers to Ruby?
 
Similar Threads
Ruby: the new Perl ? (syntax sugar that kills, too many ways to write stuff)
Ruby in practice question: Do UTF-8 and Ruby fit well in practice?
Developing location aware apps
How to study Design Patterns?
Does the scripting language beat down java?