Re: making perl more forgiving
by perrin (Chancellor) on May 15, 2004 at 20:56 UTC
|
More forgiving? It's already so forgiving that it's as if you slept with all of its best friends and it still wants to make you dinner! Relationships take work. Even if you won't turn on strict, you could at least wear matching quotes. | [reply] |
Re: making perl more forgiving
by Abigail-II (Bishop) on May 15, 2004 at 23:12 UTC
|
for example: print "fox': would still run correctly! and print literally "fox".
Well, it isn't that hard to modify perl to allow that. Of course, as soon as you have a perl that allows that, you'll come crying "how do I print a sentence with a quote in it?", because if you write:
print "O'Reilly";
your perl is going to think the string ends after the O.
Besides, if you can use either quote, what's this going to print:
my $value = 7;
print "The value is $value';
will it do interpolation or not? And how many terminating delimiters are you going to allow if you start a string with qq !?
Abigail
| [reply] [d/l] [select] |
|
|
It should do interpolation: interpolate the variable
${value::;}
| [reply] [d/l] |
Re: making perl more forgiving
by hossman (Prior) on May 15, 2004 at 23:49 UTC
|
This is one of the strangest questions i've ever seen.
Asking this question about strings, quotes, and printing in perl, is roughly equivilent to asking this perl math question...
Is there a way for me to make the perl interpreter more forgiving and ignore certain mathematical syntax errors? for example: if i type 55 +- 3, it should know that I button mashed the +/- keys and it should still run correctly and return 58. I don't even care if it can give me exactly what I want. for example returning 63 would be fine. thanks in advance!
| [reply] |
|
|
print 55 +- 3;
__END__
52
| [reply] [d/l] |
Re: making perl more forgiving
by haoess (Curate) on May 15, 2004 at 19:36 UTC
|
Nothing is impossible, but quoting errors can be easily avoided when using an editor which does syntax highlighting.
Nevertheless:
#!perl
use warnings;
use strict;
BEGIN {
$SIG{__DIE__} = sub { print "foxxy"; exit; }
}
print "fox'
__END__
-- Frank | [reply] [d/l] |
Re: making perl more forgiving
by Anonymous Monk on May 15, 2004 at 21:15 UTC
|
From Symbol::Approx::Sub docs:
This is _really_ stupid. This module allows you to call subroutines by _approximate_
names. Why you would ever want to do this is a complete mystery to me. It was written as
an experiment to see how well I understood typeglobs and AUTOLOADing.
To use it, simply include the line:
use Symbol::Approx::Sub;
somewhere in your program. Then each time you call a subroutine that doesn't exist in the
the current package Perl will search for a subroutine with approximately the same name.
Is this going to be forgiving enough? :-)
| [reply] [d/l] |
Re: making perl more forgiving
by pbeckingham (Parson) on May 15, 2004 at 19:20 UTC
|
I can't make up my mind whether you are asking for an advanced auto-correct/intellisense feature, or whether you want the interpreter to compensate for a developer not knowing that quotes must balance, or which keyword is which.
The former belongs in an editor or IDE, and the latter is just ridiculous.
| [reply] |
Re: making perl more forgiving
by jepri (Parson) on May 16, 2004 at 00:36 UTC
|
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.
| [reply] |
|
|
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
| [reply] |
|
|
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.
| [reply] |
|
|
|
|
A reply falls below the community's threshold of quality. You may see it by logging in.
|
|
|
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.
| [reply] |
|
|
| [reply] |
Re: making perl more forgiving
by ambrus (Abbot) on May 15, 2004 at 18:54 UTC
|
Program in TeX, that's the most forgiving language ever.
| [reply] |
Re: making perl more forgiving
by b10m (Vicar) on May 16, 2004 at 10:52 UTC
|
I can't help it but to think of HTML here. MS Internet Explorer is very idiot-forgiving, meaning, if you write crappy HTML (and close half the tags you need to), IE will still show the result somewhat how the author intended it.
This contributed in the many horrible WYSIWYG editors spitting out horrible HTML... and the WYSIWYG-on-your-computer-only idea.
If you just write your perl code right, you won't need a forgiving interpreter. And the example you gave just shows me you rather want to be lazy than to actually debug your code.
--
b10m
All code is usually tested, but rarely trusted.
| [reply] |
|
|
I see perl as a language. It could even be called like this...
perl -RTFM myscript.pl
And the compiler could suppose everything that is not stated or that is badly declared.
But in the end, it is like people that use to say everything with only 100 words. (x.e.politicians, astrollogers, prophets,etc.). Everybody gets the illusion that they are saying what they want to hear. The level of effective comunication, is lowered at it's minimum. So, on the other hand, it may happen that one day I am speaking the truth about something, and everybody yet want's to punish me.
There are times when precission is imperative. I believe that the level of effectiveness of a programming language resides in the limitations that the compiler imposses to the user. Yet, perl has done miracles in this aspect. So, it forgives a lot if you ignore the key words that gives you the required 'extra' precission.
.{\('v')/}
_`(___)' __________________________
| [reply] [d/l] |
|
|
| [reply] |
|
|
| [reply] |
|
|
This is a very useful analogy, and serves to underline my initial reaction that improving perl's error recovery is a possible and useful thing to do, but that this particular example (of mismatched quotes) is probably a really bad example. Consider what IE (or any other browser) does if you inadvertently replace a tag-close '>' with, say, a '<'.
Hugo
| [reply] |
Re: making perl more forgiving
by dimar (Curate) on May 16, 2004 at 20:12 UTC
|
At first glance, this is a strange question. However, I think it's a very revealing question because it demonstrates a fundamental misconception that people have about the way programming 'languages' work.
Consider this, it may give you an epiphany:
Whenever you read code in *any* programming language, it is only a *conjured-up side-effect* that the little symbols on the screen have any similarity whatsoever with 'human language'.
Consider that and let it sink in for a bit...
Did it sink in?
Still pondering that? If you get the point, then you realize that ...
print 'Hello';
print "Hello";
... is the same thing as ...
qublloogg @xux_nono_interpo@Hello@xux_nono_interpo@@uxx@
qublloogg @xux_ouio_interpo@Hello@xux_ouio_interpo@@uxx@
both are 'isomorphic', one just happens to be easier for some people to understand, read, and memorize than the other. (personal preference dictates what is 'easier' more than *anything else*!!) If someone tells you that programming 'language' X is 'more or less forgiving' (aka better, superior, smarter) than language Y, just nod your head and politely smile ... knowing that it is all a conjurer's trick.
This is why JAPH's and Obfuscation contests are so fascinating. This is why JAPH's and Obfuscation works in the first place. This is why there will always be 'new' programming languages. (or 'improvements' on existing ones). This is why people can be fooled by 'bots' into thinking they are talking to a human.
It is only a *conjured-up side-effect* that the little symbols on the screen have any correlation whatsoever with what you understand as 'human hanguage'. Understand that a 'programming language' does not work like 'human language' ... let that concept sink in.
| [reply] [d/l] [select] |
Re: making perl more forgiving
by doom (Deacon) on May 16, 2004 at 23:10 UTC
|
Well, this certainly is a strange thought, but strange
thoughts are what perl is about, and I kind of like this
one. There isn't any reason to assume that perl by default
gets the right level of finickiness... most of us prefer to
turn on use strict; pretty early in the development process, but I think there's a certain logic
to providing a use sloppy; pragma for people who
are into it.
Of course, there are undoubtably some major hassles with
implementing this kind of thing, and it probably isn't really worth doing, but still, I don't see any reason to jump down the fellow's throat about it...
| [reply] [d/l] [select] |