-
Notifications
You must be signed in to change notification settings - Fork 585
add a new warning against using \ in qw() #23403
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: blead
Are you sure you want to change the base?
Conversation
I've seen AI-generated code try to use qw() to create lists containing strings with embedded whitespace using qw and \ to "protect" the whitespace. Things like: my @list = qw( foo bar\ baz ); Just like occurences of ',' and '#', I believe this should warn. Note that the warning will only be emitted when the \ is followed by actual whitespace, so code like the following (from lib/App/Cpan.pm) will not warn: my $epic_fail_words = join '|', qw( Error stop(?:ping)? problems force not unsupported fail(?:ed)? Cannot\s+install );
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you ever seen this backslash-to-escape-whitespace-in-qw in code written by a human?
If not, then maybe we should not apply this p.r. so that we have a way to readily identify AI-generated code.
|
||
(W qw) qw() lists contain items separated by whitespace; contrary to | ||
what some might expect, backslash characters cannot be used to "protect" | ||
whitespace from being split, but are instead treated at literal data. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't you want treated as
rather than treated at
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this is a typo. Thanks.
This is adding a warning that the code will not do what was expected, which would not affect "identifying" the code. It seems a reasonable indication to me. |
I saw this in AI-generated code, but it looked plausible enough that I had to double-check. ("What?! I didn't know you could do that... Oh. It turns out you can't." "You are absolutely right!") Given the ubiquity of backlash as an escape character, it's reasonable to think that someone not fluent in Perl would try it. The example in the description is what actually led me to show the warning only when immediately followed by whitespace. |
This sounds like this warning will punishing people who actually write code and run it in production just to make it slightly more convenient for people who do not write code to copy/paste generated nonsense. Is that valuable? Nobody "fixed the language" when the markov bot on IRC produced code that almost looks right. And if that is useful, I think that at absolute minimum the request should come from an actual person who's had this problem. I don't think perl should pro-actively change in response to "umm, i saw a screen shot of a tweet on reddit that got cross-posted to my telegram group where chatGPT was wrong about programming". Nobody reported this bug. Nobody ran this code. Nobody even wrote this code. I think the same person should fix it. |
Who uses I think it's going to be the same person who reported the bug, ran and wrote such code. (Nobody.) To be honest, I'm not surprised nobody reported the absence of a warning. The bug is not the absence of a warning, it's the expectation that However, in my first encounter with AI-generated Perl code in a realistic Perl project, the AI spit that out. I think this kind of "you're holding it wrong" warning will only show up for someone (or something 🤖) who makes that very understandable mistake of assuming you can protect whitespace with backlashes. And that is exactly the kind of helpful warning Perl has been dispensing for a very long time. It could be argued that allowing |
I've seen AI-generated code try to use qw() to create lists containing strings with embedded whitespace using qw and \ to "protect" the whitespace. Things like:
Just like occurences of ',' and '#', I believe this should warn.
Note that the warning will only be emitted when the \ is followed by actual whitespace, so code like the following (from lib/App/Cpan.pm) will not warn: