Eero Saynatkari
10/13/2006 5:03:00 AM
On 2006.10.13 13:34, Kenneth McDonald wrote:
> 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 trace.
>
> 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.
I can honestly say that I have never had this issue. I can see
that it might be worrying but it is just like any other language
feature--when you know it, you plan for it, you write your code
with it in mind.
And this is not to say it is a terrible inconvenience to have
to do this. The code seems to be more natural than with error
handling.
Oh--Arrays, not lists :)