On 21.11.2006 23:28, Leslie Viljoen wrote:
> On 11/21/06, Charles D Hixson <charleshixsn / earthlink.net> wrote:
>> David Vallner wrote:
>> In this case the bug was in the message not stating which variable had a
>> nil value.  You may not think of it as serious, but he reports spending
>> several hours on it, and I'd call that a bug.

Frankly, in this case I would attribute that to the bug searcher and not 
the language.  The message is pretty clear, it gives a line number and 
an easy explanation.  With that, you can immediately spot where it goes 
wrong - even if you are unsure whether to look at the right or left side 
of the "+".

>> Remember, Ruby is being recommended to total neophytes as a good
>> language to start with.  That means that good diagnostic error messages
>> are essential!
> 
> I have also previously requested that this get fixed in a future Ruby.
> It's very annoying to try and guess which could be the offending
> variable in a complex expression, and it wastes a lot of time. It
> would surely be very easy for Ruby to say which variable was nil.

Actually I am not sure about this.  The reason is this: the fact that 
the method does not exist in the receiver is not detected prior to 
runtime.  And the object in question could potentially be referenced via 
any number of variables (including being part of an Array).  As such the 
interpreter would have to remember several variable names per thread per 
object to actually be able to resolve this properly.  Or it would have 
to go back to the source to determine this.  And what do you do in this 
case where it is the result of a method call?  As you see, it is not 
that easy and can incur some overhead you might not want to pay either.

Having said that, nobody forces you to create complex expressions.  You 
can help readability and maintainability a lot if you break those down - 
which in turn makes debugging easier.

> In some of my latest scripts I have this:
> 
> def preventNil(*args)
>  args.each_with_index do |arg, i|
>    raise ArgumentError.new("argument #{i} cannot be nil") if arg.nil?
>  end
> end

> I'd be interested to hear if there are nicer solutions to this problem.

The problem I see here is that the fact it's not nil does not tell you 
that it is actually a proper value.  So at best you only catch some 
errors with this approach.

Kind regards

	robert