As a Python user starting to mess around with Ruby, one of my biggest
concerns is the fact that so many operations on lists ‘fail silently’
(return nil) when given list indices that are out of bounds. In
particular, I worry that this might produce hard-to-track down errors,
as the problem might not show up until one tries to do something with
the returned value(s); and by that may be somewhere far away in the
code. Certainly the guilty list access won’t show up in the call stack.
On the other hand, it’s often thought that dynamic languages will result
in lots of difficult-to-find problems due to the lack of strong typing,
but both Python and Ruby users know that’s not the case.
So my question is, in practice, how difficult is it to track down
index-out-of-bounds-errors in Ruby? It can certainly be a godawful
problem in C, and I’m pretty sure it would be in Python, too, if
exceptions weren’t thrown. And in Ruby, how does one track done where
such errors actually occur? In Python, I can simply look at the stack
This isn’t a criticism of Ruby. (Well, one aspect maybe). I’m looking at
Ruby because there are a lot of things (documentation tools,
consistency, gems, others) that it does better than Python. But I do
worry about silent index errors.