[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Syntax checker wtf?

Firstname Surname

8/18/2006 6:11:00 AM

I'm new to Ruby and RoR; I was messing around with it today and had
trouble with error codes. Specifically, the ruby syntax checker
frequently spits out 'syntax error' with the last line of the code as
the error line (the error is nowhere near the last line). This happens
with missing chars, extra ., all sorts of minor syntax errors, not just
missing 'end's. I found myself copy and pasting functions, checking,
then pasting again to find the error, which is pretty ridiculous.

This is something I'd expect in a pre 1.0 compiler, but ruby is at
1.8.4; is the
ruby syntax checker just really primitive?
This isn't very user friendly, especially for a newbie, is there a more
precise syntax checker that can actually point closer to the error line
# a
high % of the time?


Cheers,
Newb

--
Posted via http://www.ruby-....

46 Answers

Phillip Hutchings

8/18/2006 6:19:00 AM

0

On 8/18/06, Firstname Surname <rubyforum@wendlink.com> wrote:
> I'm new to Ruby and RoR; I was messing around with it today and had
> trouble with error codes. Specifically, the ruby syntax checker
> frequently spits out 'syntax error' with the last line of the code as
> the error line (the error is nowhere near the last line). This happens
> with missing chars, extra ., all sorts of minor syntax errors, not just
> missing 'end's. I found myself copy and pasting functions, checking,
> then pasting again to find the error, which is pretty ridiculous.
>
> This is something I'd expect in a pre 1.0 compiler, but ruby is at
> 1.8.4; is the
> ruby syntax checker just really primitive?
> This isn't very user friendly, especially for a newbie, is there a more
> precise syntax checker that can actually point closer to the error line
> # a
> high % of the time?

No, it's just that Ruby is so flexible that your incorrect syntax
could well be right if you tidied it up at the end.

--
Phillip Hutchings
http://www.sit...

Robert Klemme

8/18/2006 6:22:00 AM

0

Firstname Surname wrote:
> I'm new to Ruby and RoR; I was messing around with it today and had
> trouble with error codes. Specifically, the ruby syntax checker
> frequently spits out 'syntax error' with the last line of the code as
> the error line (the error is nowhere near the last line). This happens
> with missing chars, extra ., all sorts of minor syntax errors, not just
> missing 'end's. I found myself copy and pasting functions, checking,
> then pasting again to find the error, which is pretty ridiculous.
>
> This is something I'd expect in a pre 1.0 compiler, but ruby is at
> 1.8.4; is the
> ruby syntax checker just really primitive?
> This isn't very user friendly, especially for a newbie, is there a more
> precise syntax checker that can actually point closer to the error line
> # a
> high % of the time?

I *think* this is at least partly due to Ruby's convenient and very
flexible syntax. IOW, the parser has no means to detect the error line
as it could be in several places - likely too many to report. Also,
this is how parsers work. From my limited insight into the parser
generation business it would require a) a different parser generator
that is much smarter or b) a lot of effort that it's not worth IMHO.

I'll have to add that this is rarely an issue for me. Maybe you should
use an editor with automatic bracket closing and "end" insertion.

Kind regards

robert

Firstname Surname

8/18/2006 6:25:00 AM

0

Phillip Hutchings wrote:
> On 8/18/06, Firstname Surname <rubyforum@wendlink.com> wrote:
>> ruby syntax checker just really primitive?
>> This isn't very user friendly, especially for a newbie, is there a more
>> precise syntax checker that can actually point closer to the error line
>> # a
>> high % of the time?
>
> No, it's just that Ruby is so flexible that your incorrect syntax
> could well be right if you tidied it up at the end.

It's not a bug, it's a feature! Geeze, django is looking better already.

--
Posted via http://www.ruby-....

Just Another Victim of the Ambient Morality

8/18/2006 6:45:00 AM

0


"Firstname Surname" <rubyforum@wendlink.com> wrote in message
news:80ebfecc5915f6feffed6fa20fde07e8@example.com...
> I'm new to Ruby and RoR; I was messing around with it today and had
> trouble with error codes. Specifically, the ruby syntax checker
> frequently spits out 'syntax error' with the last line of the code as
> the error line (the error is nowhere near the last line). This happens
> with missing chars, extra ., all sorts of minor syntax errors, not just
> missing 'end's. I found myself copy and pasting functions, checking,
> then pasting again to find the error, which is pretty ridiculous.
>
> This is something I'd expect in a pre 1.0 compiler, but ruby is at
> 1.8.4; is the
> ruby syntax checker just really primitive?
> This isn't very user friendly, especially for a newbie, is there a more
> precise syntax checker that can actually point closer to the error line
> # a
> high % of the time?

While I'm a newbie myself, I'm willing to guess that there's little you
can do about this problem except to try to relax and be a little more
careful with your code.
To be honest, I really don't think this problem is particularly bad in
Ruby. I don't know exactly what kind of errors you're making (and perhaps
you can elaborate some more on that) but even the latest Microsoft C++
compiler often gives less than helpful clues on the source of the problem,
or even it's location! Brace mismatching and quote mismatching are two
errors that neither parsers can nail down to your satisfaction and I get the
sense that these constitute the majority of your problems (again, please
elaborate on this). The former can be alleviated by proper indentation and
the latter can be totally eliminated by syntax highlighting, although I
don't use this technique myself (since I'm a lazy gvim user).



Gregor Kopp

8/18/2006 6:55:00 AM

0

As "Firstname Surname" said, the error messages from the ruby
interpreter are not really significant, they could be more verbose.
Maybe Ruby 2.0 will do it better.
However, a good editor may help, but it can not be the solution, or?

Regards, Gregor



Robert Klemme schrieb:
>
> I'll have to add that this is rarely an issue for me. Maybe you should
> use an editor with automatic bracket closing and "end" insertion.
>
> Kind regards
>
> robert
>

Firstname Surname

8/18/2006 7:59:00 AM

0

Gregor Kopp wrote:
> As "Firstname Surname" said, the error messages from the ruby
> interpreter are not really significant, they could be more verbose.
> Maybe Ruby 2.0 will do it better.
> However, a good editor may help, but it can not be the solution, or?
>
> Regards, Gregor
>
>
>
> Robert Klemme schrieb:

I think the syntax checker could be a little more verbose, and I don't
think it would take much work.

The trouble I had was with a line that had an extra '.' like:
@entry = Entry.find(params[:id].
instead of
@entry = Entry.find(params[:id]

and another error that i think was just a missing bracket maybe like
@entry = Entry.find(params[:id

I've used many different languages with various levels of syntax error
help, but never one this bad. I just wrote a quick script to remove
functions from 'def' to 'end' in order and check the syntax over, thus
quickly finding which function the error is in. This is a lot better
than looking through a couple hundred line controller file. If I can do
this in 10 minutes, I can't help but think it's just laziness on the
part of the syntax checker not to provide at least hints where it thinks
the problem might be.
I understand that ruby is flexible (I'm not not sure this is a merit
when using for a large web app), but the checker could easily check
based on 'standard' expected syntax and be more helpful about error
location 99% of the time.




--
Posted via http://www.ruby-....

David Vallner

8/18/2006 9:52:00 AM

0

On Fri, 18 Aug 2006 09:58:31 +0200, Firstname Surname
<rubyforum@wendlink.com> wrote:
> the checker could easily check
> based on 'standard' expected syntax and be more helpful about error
> location 99% of the time.

That's what a lint style program would do, not the compiler. Compilers are
there to check correctness against the formal language definition, not to
make opinions about your code, and quoting James Britt: Ruby assumes the
developer is a grown-up. If you're newbly enough to make trivial syntax
errors, noone's forcing you to use the language.

If you think the syntax checking in the compiler could be made better, go
ahead and hack the parser to do it. But I don't recall this topic being
present on the list and complained about any often or so vocally, so I
doubt it's critical that effort be spent from the core Ruby developer team
in that direction.

Oh, before I forget: Whining gets you nowhere, and trolling belongs to
slashdot. Cut that out.

David Vallner

Just Another Victim of the Ambient Morality

8/18/2006 10:08:00 AM

0


"Firstname Surname" <rubyforum@wendlink.com> wrote in message
news:a466c7740a34c06801792de17814b637@example.com...
>
> I think the syntax checker could be a little more verbose, and I don't
> think it would take much work.

There's a standard response to comments like this. The code is open
source, so if you really think it's that easy, why don't _you_ do it? It
works better for wikis...


> The trouble I had was with a line that had an extra '.' like:
> @entry = Entry.find(params[:id].
> instead of
> @entry = Entry.find(params[:id]
>
> and another error that i think was just a missing bracket maybe like
> @entry = Entry.find(params[:id
>
> I've used many different languages with various levels of syntax error
> help, but never one this bad. I just wrote a quick script to remove
> functions from 'def' to 'end' in order and check the syntax over, thus
> quickly finding which function the error is in. This is a lot better
> than looking through a couple hundred line controller file. If I can do
> this in 10 minutes, I can't help but think it's just laziness on the
> part of the syntax checker not to provide at least hints where it thinks
> the problem might be.

Okay, judging from your examples, I think the problem is that you're
hitting a rather sore spot in the Ruby interpreter. I've done a few
examples and it looks as if the Ruby parser does a lazy evaluation of
parenthesized (and bracketed) things. It just so happens that these are
exactly the kind of mistakes you make so they really seem to bite you.
The only thing I can suggest is that you close all your brackets and
functions before filling them. So, while editing, you'll write things in
this order:

def some_function
end

..and then...

def some_method
@member[]
end

...and finally...

def some_method
@member[@other + 2]
end


> I understand that ruby is flexible (I'm not not sure this is a merit
> when using for a large web app), but the checker could easily check
> based on 'standard' expected syntax and be more helpful about error
> location 99% of the time.

Well, you're welcome to try Django but you should be warned that the
Python syntax is every bit as flexable as Ruby, so if you really don't
think that's a merit for a large web application...
Python software is generally more mature than Ruby (probably because
it's much older) but the syntax is less consistent (perhaps because it's
much older?), so it's a trade off. You'll have to decide what's important
to you and go from there...
Good luck!



Just Another Victim of the Ambient Morality

8/18/2006 10:29:00 AM

0


"David Vallner" <david@vallner.net> wrote in message
news:op.teg4b0gclyznzu@new.chello.sk...
> On Fri, 18 Aug 2006 09:58:31 +0200, Firstname Surname
> <rubyforum@wendlink.com> wrote:
>> the checker could easily check
>> based on 'standard' expected syntax and be more helpful about error
>> location 99% of the time.
>
> That's what a lint style program would do, not the compiler. Compilers
> are there to check correctness against the formal language definition,
> not to make opinions about your code, and quoting James Britt: Ruby
> assumes the developer is a grown-up. If you're newbly enough to make
> trivial syntax errors, noone's forcing you to use the language.

That's sufficiently harsh that it's rather unfair.
Okay, so you fed the interpeter bad input but, you know what? Good
software tells you why your input was bad and the original poster isn't
getting the feedback he was hoping to get. Now, perhaps his expectations
aren't realistic but you can simply tell him why they're not realistic
rather than effectively telling him that he just sucks...

Personally, I don't think there's anything wrong with protecting code
from human error considering how it's written for humans. Ruby still has
access permissions. If Ruby really trusted the programmer, it wouldn't
bother with public and private methods. If you're not supposed to call
that method, then don't call it! It's that simple. That's what Python
does...


> If you think the syntax checking in the compiler could be made better, go
> ahead and hack the parser to do it. But I don't recall this topic being
> present on the list and complained about any often or so vocally, so I
> doubt it's critical that effort be spent from the core Ruby developer
> team in that direction.

Well, it may be true that we have better things to do (I, too, have
never encountered the problems the original poster is having), but he's
simply telling us what he finds important. If enough people complained
about it, I'd imagine work would be done on the problem...


> Oh, before I forget: Whining gets you nowhere, and trolling belongs to
> slashdot. Cut that out.

You could cut him some slack. It's pretty easy to get frustrated with
these stupid machines. A lot of things really should "just work" and it
can get frustrating when they don't, especially after everyone proselytizes
it as the solution to all their problems...




Paul Battley

8/18/2006 10:47:00 AM

0

On 18/08/06, Just Another Victim of the Ambient Morality
<ihatespam@rogers.com> wrote:
> Personally, I don't think there's anything wrong with protecting code
> from human error considering how it's written for humans. Ruby still has
> access permissions. If Ruby really trusted the programmer, it wouldn't
> bother with public and private methods. If you're not supposed to call
> that method, then don't call it! It's that simple. That's what Python
> does...

Ruby does trust the programmer. The privacy screen is very flimsy:

class Foo
private
def dont_call_me
puts("I said DON'T CALL ME!")
end
end

f = Foo.new
f.dont_call_me
# NoMethodError: private method `dont_call_me' called for #<Foo:0x34293c>

f.__send__(:dont_call_me)
# I said DON'T CALL ME!

Paul.