Perl-Critic / Perl-Critic

The leading static analyzer for Perl. Configurable, extensible, powerful.
http://perlcritic.com
Other
181 stars 103 forks source link

Feature request: New policy that complains about three dot range operator in foreach range. #614

Open MLRiain opened 9 years ago

MLRiain commented 9 years ago

Using three dots in a foreach range instead of two is passed over. Example: foreach my $item ( 0 ... $max ) instead of: foreach my $item ( 0 .. $max )

clonezone commented 9 years ago

Perl::Critic does not work on syntactically invalid code. If it attempted to, it would have to take arbitrary input and attempt to do something with it, e.g. an MP3 file. ;]

moregan commented 9 years ago

"..." is a valid variation on "..". see perldoc perlop for details. E.g. in perl 5.6.2:

perl -wle 'for ( 1 ... 2 ) { print $_ }'
1
2
thaljef commented 9 years ago

As I understand perlop, both should produce the same result in list context. So would the policy be to prohibit ... in list context (presumably because .. is better known)?

szabgab commented 9 years ago

I was the one who recommended the OP to post this. I've never seen ... used in such context (and probably never in list context in general) and I think it should be discouraged. It is confusing. So what @thaljef said.

I am also sad to see @clonezone jumping the gun so quickly. That code was syntactically correct and did exactly the same as the .. would have done.

thaljef commented 9 years ago

I am also sad to see @clonezone jumping the gun so quickly

It just goes to show how obscure the ... operator is. I would have made the same conclusion if @moregan hadn't spoken up.

clonezone commented 9 years ago

Sorry, @szabgab, but the subject does say "syntax error", and I followed on from that.

clonezone commented 9 years ago

Changed the issue name to something that does not include the words "syntax error".

szabgab commented 9 years ago

@clonezone you are right. I have not noticed that the title says syntax error. Then I understand your comment.