develooper Front page | perl.perl5.porters | Postings from April 2010

Re: RFC: Perl manual pages -- update to follow the perlstyle.pod guidelines

Thread Previous | Thread Next
Tom Christiansen
April 3, 2010 15:54
Re: RFC: Perl manual pages -- update to follow the perlstyle.pod guidelines
Message ID:
> This would suggest that in simple contexts, presenting the basic
> function use could be done without prens.

> Tom was inclined to concur, provided I understood correct, to use:

>    if (length $var)        for (sort keys %hash)

> instead of

>    if (length($var))       for (sort(keys(%hash)))

Yes, that's right.  So long as no one need know prototypes just
to figure out which arguments go where, there's no ambiguity
and therefore the parens don't matter.  Removing them changes
nothing and risks no confusion, so it seems cleaner without them.

It's when you have to know things like how a bunch of functions 
in a single expression cluster up together depending on stealth
prototypes of () vs ($) vs ($$) vs (@) and so on and so forth
that I get bothered.  These are the same:

    $oct_perms = sprintf("%#o", $perms);
    $oct_perms = sprintf "%#o", $perms;

as are these:

    printf("perms=%#o\n", $perms);
    printf "perms=%#o\n", $perms;

But it's easy to have expressions where you need to know the
prototype or which are just confusing otherwise.

I think the only function I tend to let slide is scalar() (see
previous mail), which I guess I must somehow think of as a type
cast, even though I know what it really is.


However, I really am a functions-get-parens-around-their-args
kinda guy.  That's why I never need the spelt-out and/or/not.
Even when faced with 

    @statinfo = stat($path) or die "can't stat $path: $!";

I am so averse to the spelt versions than I would write that
any of 

  ## 1 ##
    (@statinfo = stat($path)) 	|| die "can't stat $path: $!";

  ## 2 ##
    @statinfo = stat($path);
    @statinfo			|| die "can't stat $path: $!";

  ## 3 ##
    unless (@statinfo = stat($path)) {
	die "can't stat $path: $!";

rather than have to write or.  I simply do not use it.  I understand
precedent with respect to list ops and && and ||, and I use parens
nearly religiously.  I would always rather write:

    close(FH) || die "can't close $path: $!";

than ever, ever write:

    close FH or die "can't close $path: $!";

because close, FH, or, and die all have the same lexical nature: they're
all idents.  That cascade of idents *really* bugs me.  My mind super really
wants the () and the || to break things up for quick visual parsing.
It takes me much, much longer to read 

    close FH or die "can't close $path: $!";

than it takes me to read:

    close(FH) || die "can't close $path: $!";

That's just how I am.


Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About