in reply to making perl more forgiving

Your question is interesting, and it's a shame that the answers to your question don't contain much more than "that's ridiculous". Clearly a lot of thought went into those answers. Not.

Regarding your suggestion. Since perl already detects runaway strings, it would be nice to have the compiler say "I found a runaway string starting with "foxx', but if I change your ' to a " then I can compile it.

Perhaps in perl6 we could have a module that fires up when the compile fails and tries to mangle the code near the syntax error until it compiles.

Nice idea, I'll have to think about it some more.

Update: I suspect that this is getting downvotes because people don't like the idea of a compiler automatically correcting their mistakes. I don't like that idea either. But I do like the idea of a compiler printing out "syntax error at line 65, did you mean 'print "foxx"' instead?"

They should put a feature like this in Perl. Oh wait! They already did.

Thanks to chromatic for the correction.

____________________
Jeremy
I didn't believe in evil until I dated it.

Replies are listed 'Best First'.
Re: making perl more forgiving
by Abigail-II (Bishop) on May 16, 2004 at 01:15 UTC
    Since perl already detects runaway strings
    The fact that a compiler can figure out that you forgot to close off a string doesn't mean the compiler has any idea where this happened.
    Perhaps in perl6 we could have a module that fires up when the compile fails and tries to mangle the code near the syntax error until it compiles.
    What would be the point? Clearly it can't do it silently because it might mangle it to something that compiles, but doesn't do what the programmer intended. OTOH, if it can't be silenced, the programmer wants to fix the mistake anyway, because otherwise the compiler will split out messages each time the program is run.
    I suspect that this is getting downvotes because people don't like the idea of a compiler automatically correcting their mistakes.
    I think a compiler that automatically corrects mistakes would be wonderful. I'm sure that someone who manages to make a compiler that corrects mistakes correctly has a pretty good chance of winning a Turing award.
    But I do like the idea of a compiler printing out "syntax error at line 65, did you mean 'print "foxx"' instead?"
    How much different from "Might be a runaway multi-line "" string starting on line N" is that?

    Abigail

      Well, I had my epiphany in the chatbox, so I might as well share.

      If the compiler worked like a spell checker, it could pop up a dialog and say "Detected a syntax error xxx, I think you should change your code to yyy. Shall I change it?"

      I spend a lot of my debugging time nailing spelling errors and missing braces. I'd rather the compiler took a guess and asked me if it was right. Pressing 'y' five times would be so much nicer than having to get back into the text editor 5 times. And if I have to press 'n' and fix it by hand, I've lost nothing.

      How much different from "Might be a runaway multi-line "" string starting on line N" is that?

      Just as a more useful example, why not use Symbol::Approx to guess what function I misspelled, and then suggest the correction to me?

      Or how about 'Detected missing semicolon at line 33, shall I correct?' Why is it a good use of my time to correct this trivial problem by hand?

      Or how about "Unmatched left brace at line 133, but if I pop a brace in front of the next 'sub xxx', I can compile. Want me to fix it?"

      ____________________
      Jeremy
      I didn't believe in evil until I dated it.

        Patches welcome.

        Abigail

      A reply falls below the community's threshold of quality. You may see it by logging in.
Re: Re: making perl more forgiving
by chromatic (Archbishop) on May 16, 2004 at 08:34 UTC
    We should put a feature like this in Perl. Oh wait! We already did.

    I've always been leery of the "why don't we fix something?" comments. Many of them come from people who aren't willing (or even capable of doing the work they suggest. It feels rather dishumble to take credit for the features of Perl that you like if you're not willing to take the blame for the features you don't like. Doubly so if you haven't contributed patches.

    Update: edited a bit to be more gentle.

      That intent was most definately not there. The context in my mind when I wrote the comment was an impersonal 'we', as in "Hey, how about we (somebody) fix this?". In real life, my tone of voice and inflection would have made it clear.

      I mention further down in the discussion Perl5 is too scary for me - that's hardly the sort of thing someone says when attempting to steal someone elses work.

      OTOH thanks for pointing it out gently.

      ____________________
      Jeremy
      I didn't believe in evil until I dated it.