Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

petdance (2468)

petdance
  andy@petdance.com
http://www.perlbuzz.com/
AOL IM: petdance (Add Buddy, Send Message)
Yahoo! ID: petdance (Add User, Send Message)
Jabber: petdance@gmail.com

I'm Andy Lester, and I like to test stuff. I also write for the Perl Journal, and do tech edits on books. Sometimes I write code, too.

Journal of petdance (2468)

Friday July 14, 2006
11:33 PM

My first batch of Perl::Critic extensions

[ #30296 ]
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:

  • ProhibitCommentedOutCode

    Commented-out code is usually noise. It should be removed.

  • ProhibitFlagComments

    Watch for comments like ``XXX'', ``TODO'', etc.

  • ProhibitNoPlan

    Tests should have a plan.

  • ProhibitNumberedNames

    Variables like $user and $user2 are insufficiently distinguished.

  • ProhibitRefProtoOrProto

    Determining the class in a constructor by using ref($proto) || $proto is usually a cut-n-paste that is incorrect.

  • ProhibitVagueNames

    Vague variables like $data or $info are not descriptive enough.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • Why would you prohibit those? I think there would be more valid reasons to have flag comments than not. But I could just not have been explanation that proves otherwise.
  • 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

    my $class = ref $self || $self
    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.
    --
    J. David works really hard, has a passion for writing good software, and knows many of the world's best Perl programmers
      • 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. :)

        --
        J. David works really hard, has a passion for writing good software, and knows many of the world's best Perl programmers
    • 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?

      • 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?"

        --
        J. David works really hard, has a passion for writing good software, and knows many of the world's best Perl programmers
        • Yeah, it's been in perltoot forever. But it's no longer there. Randal or I (not sure who) have yanked it.
          --

          --
          xoa

          • Good. That should solve the problem for future budding Perl programmers.

            Heh; my children will probably learn object-oriented programming from Perl's documentation. :)

            --
            J. David works really hard, has a passion for writing good software, and knows many of the world's best Perl programmers
        • 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.