• 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Junilu Lacar
  • Tim Cooke
  • Jeanne Boyarsky
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Piet Souris
  • salvin francis
  • fred rosenberger
  • Frits Walraven

Common obstacles for newcomers to Ruby?

Ranch Hand
Posts: 235
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?

Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 = Array.new

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.
Michael Sullivan
Ranch Hand
Posts: 235
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
Try 100 things. 2 will work out, but you will never know in advance which 2. This tiny ad might be one:
Two software engineers solve most of the world's problems in one K&R sized book
    Bookmark Topic Watch Topic
  • New Topic