From: Eivind Eklund Date: 2004-10-07T01:43:52+09:00 Subject: Re: quality of error messages On Wed, 6 Oct 2004 22:48:49 +0900, Joachim Wuttke wrote: > Hi Ruby developers, > > after spending some time with Perl and Python, I am > currently exploring Ruby. While I am quite enthusiastic > about some of its features, I am increasingly preocuppied > about the difficulties to localize errors. > > Example 1: missing "end" in > -> 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 ? This is parser-technically hard to do; maybe it would be possible to look at when indenting got wrong, but I suspect that would be hard to add into the present lex/yacc style parser factoring. On a separate note: I have very few problems with this; I also program in Perl, and get a lot more problems of this kind in Perl. I can think of a few of my practices that minimize the problem: - I always write the opening and closing delimiters for a statement at the same time and then fill in data between them - I use vim with hot braces and parantheses, so I see if I have a mismatch (however, this should tip the opposite direction for Ruby) - I use - I always review my diffs with -ub to find what I may have changed wrong if I get a parse error. I also do very many very small commits (and use cdiff - http://people.freebsd.org/~eivind/cdiff - to review my diffs). > 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. As others have said: You really need to adjust your thinking to Ruby here. Also, the code example you showed elsewhere in the thread had two a slight design smells: - Trying to get a variable smells of violating "Tell, don't ask" - The method chaining you do violates the "Law of Demeter" - don't dot the return value from another method. Q: "What are the consequences of violating the Law of Demeter?" A: "Joe Demeter sends his mates Largo Coupling and Minimo Cohering round to beat the shit out of your system." (Credit: Graham Perkins) Note that "Law" is a very strong statement - this is a guideline. > Developers, do you share my opinion that this would > be worth working upon ? I would really like to hear that > error messages will improve in future versions of the > interpreter. I think it is well worth making better error messages. But then again, I always think that :-) I hope the messages will be better in later versions of Ruby, and I'm sure that matz will accept patches to this effect (assuming they do not break anything else). ;-) Eivind.