Slash Boxes
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

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • I have two opposing examples of languages that are more likely to need comments than others: regexps and T-SQL (Sybase/SQL Server). One is extremely terse, one is extremely verbose.

    Regexps are usually very compact and opaque. Your comment about whitespace is spot on, so /x should obviously be encouraged. But even with a sanely laid out regexp, the pattern of a regexp usually needs comments to indicate exactly what (\w+-\d) means in the context of a program. The regexp syntax itself doesn't allow us to do t
    • When it comes to Perl, I find that using implicit $_ often obscures the code. Not using an explicit variable means a missed opportunity to self-document the code by naming the variable properly.

      I think the exact opposite. $_ has a meaning in Perl: “the current ‘thing’ being operated on”. That's a well-defined convention, and it has the advantage of being the same in every program.

      In other languages when people want a temporary variable they often use i or n or s, but they aren'

      • by jplindstrom (594) on 2004.12.20 11:33 (#36961) Journal
        Using $i as a loop variable doesn't increase readability unless it is to communicate that "it's just a loop variable" and that's seldom the case since the Perl foreach is so much more useful than the C-style for loop.

        If the code block is very brief, like in
        dostuff($_) for(@servers);
        then I agree that it isn't necessary to alias it to a new name. But if the code block is longer than a few lines, it's indeed very useful to have an actual name connected to the entity you're dealing with.

        Consider the following piece of code:
        for ($oPost->aCommentLast($no)) {
            my $oReplier = Snacks::Subscriber->oGetRandom;
            my $oReply = Snacks::Message->new(
                    oPoster => $oReplier,
                    oReplyTo => $oMessage,
                    text => $_->{text}
        Note how the my $oReply line doesn't stand alone since you have to backtrack to the loop to find out what $_ is.