From: Joel VanderWerf Date: 2006-10-13T14:14:32+09:00 Subject: Re: Silent out-of-index problems--how much of a problem are they really? Kenneth McDonald wrote: > 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. In general, ruby encourages you to use iterators more than indexing (though of course not always), which avoids the issue. In many cases, you are expecting that the array may have some nil entries, so the bounds question isn't really different from the question of whether there was a real object at that index. You have to deal with that case anyway (I presume even in python). Maybe you explicitly raise an exception when [] returns nil: elt = a[i] || (raise IndexError, "missing entry at #{i}") (of course, this will also raise an error on a false value, as well as nil). -- vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407