Brian Candler
10/6/2004 2:15:00 PM
On Wed, Oct 06, 2004 at 10:48:49PM +0900, Joachim Wuttke wrote:
> Example 1: missing "end" in <last-line-of-code>
> -> I forget to close a "class" or a "do" or a "if" block -
> but which one ? Shouldn't the system be able to name
> possible locations of unclosed block openings ?
I agree with that one. I have often has to do a 'divide and conquer': create
a temporary file, copy in one class or method, run, paste in some more, run
again, until I locate the section of code which contains the error.
I think it's difficult for a parser to know where you might have missed an
'end'. It could show you where it thinks the most recent 'do'/'def' was, but
the error could be much, much higher up.
It seems that Ruby permits nested 'defs', which makes it almost impossible
to detect the error. But since nested defs are not common, perhaps there
could be a way to track them. What about if "ruby -W3" gave a warning for a
nested 'def'? That would allow you to isolate the error to a single method,
which would make life a lot easier.
class Foo
def bar(x)
if x == 3
puts "hello"
end
def baz(y) # <-- could error here?
end
end # <-- actually errors here
> Example 2: NoMethodError: undefined method.
> -> Wrong, I defined the method. I just forgot to
> include it in the attr_reader list. The system
> shouldn't mislead me.
That error is correct - perhaps you can give an example of code where you
think it is misleading.
Remember that
@foo = "hello"
sets an instance variable, but it does NOT create a method. You can do:
def foo
@foo
end
def foo=(x)
@foo=x
end
or you can do
attr_accessor :foo
to define corresponding methods automatically, but instance variables
purposely do not automatically gain accessor methods.
Regards,
Brian.