in reply to Are there any drawbacks to comments -- can they hurt the performance of Perl code?

Personally, I think your code should make sense by itself, first and foremost. Name your variables, subroutines, packages, etc.. with descriptive terms. Use a name like get_current_standing() for a sub instead of standing()

If I develop close with another coder, nothing ticks me off more then shortcuts like these. Then the errors come in .. you track it down to a file named "sup_off.pl" that has no record of who made it, is a year old, and the whole namespace is a shortcut. Save the greek for hex! (Sorry.. venting.).

As for myself i sprinkle #TODOs and i work the pod as i go.. I keep stuff in cvs too... That's a million zillion times more important then commenting subroutines! Jeez, this doesn't sound like a perl oriented environment at all.. sounds more like javascript to me. Comments don't spit on perldoc, you know? Users and even the developers should not have to open the code to know how to use it.. but I'm just being a parrot here. But.. the parrot talk makes sense to me.

I think you want to do what is best- Not just what the goons tell you to do. So.. get a copy of Perl Best Practices, it will kick you in the nuts.. but it will also give you discipline and inspiration. Lastly.. IMHO, look at cpan modules, look at their documentation.. where are the comments there? I don't think pod will take much longer to write then ##.. besides.. You can use perldoc on any files with pod and you get nice formatted code on the screen. Leaves out the comments.

  • Comment on Re: Are there any drawbacks to comments -- can they hurt the performance of Perl code?

Replies are listed 'Best First'.
Re^2: Are there any drawbacks to comments -- can they hurt the performance of Perl code?
by Moron (Curate) on Aug 14, 2006 at 16:11 UTC
    It turns into a hellbound rathole if you take that too far though. I use a compromise approach, which is to try to make at least the variables self-explanatory where necessary, then when the routine is built and ready for the testing phase, I ask myself what additional information a maintainer (in addition of course to the mandatory change log) might need and add in comments in a single after-pass. In such cases, avoiding comments by forcing the code to be self-explanatory would also require sordid travesties of the language to be inflicted upon it. Although, when I was a total newbie and hadn't yet learned about strict references, I didn't realise back then just how horrible it actually was to do things like <travesty>:
    { no strict; return _xyz_must_have_failed_; }
    </travesty> instead of simply
    return 0; # xyz must have failed

    -M

    Free your mind