I put out my first batch of extensions to Perl::Critic, in the distro Perl-Critic-Bangs. (You'll want version 0.20, not the 0.01 that's there as I write this)
The rules come from my fluff distribution, which I guess is still useful, but Perl::Critic handles more nicely. Thanks to Andy Moore for doing most of the leg work and letting me take it from him.
The rules included with the Perl::Critic::Bangs group include:
Commented-out code is usually noise. It should be removed.
Watch for comments like ``XXX'', ``TODO'', etc.
Tests should have a plan.
Variables like $user
and $user2
are insufficiently distinguished.
Determining the class in a constructor by using ref($proto) || $proto
is usually
a cut-n-paste that is incorrect.
Vague variables like $data
or $info
are not descriptive enough.
Re:Flag comments?
sigzero on 2006-07-15T11:11:36
I should say *not* in production code though.
Determining the class in a constructor by using ref($proto) || $proto is usually a cut-n-paste that is incorrect.
Could you please elaborate? I've been using
for years. The purpose seems to be so that a method can be called as either a class method or an instance method, but I've got to admit I'm not really sure why that's so important; it has never affected me.my $class = ref $self || $self
Re:ProhibitRefProtoOrProto
petdance on 2006-07-15T12:58:09
Not exactly. Read here:
http://search.cpan.org/dist/Perl-Critic-Bangs/ProhibitRefProtoOrProto.pmRe:ProhibitRefProtoOrProto
jdavidb on 2006-07-16T00:40:10
Thank you. I hereby renounce my cargo-cultish ways.
:) Thanks also for the link to Randal's column which mentioned this. It's good to have some perspective. I've actually always thought it was a bit odd to want an instance to be useful for generating additional objects of the same class. But perltoot was the first work that taught me OO (yes, I learned OO with Perl before I ever saw Java or C++
:) ), and so I accepted it as Gospel truth at the time. :) Re:ProhibitRefProtoOrProto
chromatic on 2006-07-15T18:41:07
You've touched on part of the problem; if you don't know why a piece of code or an idiom is important, why use it?
Re:ProhibitRefProtoOrProto
jdavidb on 2006-07-16T00:41:21
Can't argue with that. Except in this case the Perl documentation told me it was important. So I sit there with cognative dissonance: my several years of experience on the subject tell me that you'd never want to do what this idiom is for. But the very work that taught me OO in the first place said to do it. Thus, I've never really said, "Why not get rid of this?"
Re:ProhibitRefProtoOrProto
petdance on 2006-07-16T00:47:33
Yeah, it's been in perltoot forever. But it's no longer there. Randal or I (not sure who) have yanked it.Re:ProhibitRefProtoOrProto
jdavidb on 2006-07-16T05:13:13
Good. That should solve the problem for future budding Perl programmers.
Heh; my children will probably learn object-oriented programming from Perl's documentation.
:) Re:ProhibitRefProtoOrProto
chromatic on 2006-07-16T07:07:42
Yeah, that's a longstanding frustration I share. I've slowly, secretly submitted documentation patches for some of the more egregious fibs of the documentation over the years.