Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Perl Misc (http://www.velocityreviews.com/forums/f67-perl-misc.html)
-   -   A preference in the style guide (http://www.velocityreviews.com/forums/t889113-a-preference-in-the-style-guide.html)

Arndt Jonasson 11-15-2004 02:19 PM

A preference in the style guide
 

I've been reading the style guide (perldoc perlstyle), and I have
trouble understanding one of the short preferences listed in the
beginning:

"Space after last parenthesis matching on current line."

Can someone give simple examples where this preference is
followed, and not followed, respectively?

(I also had problems with "uncuddled elses.", but dejanews solved that
for me - "cuddled" means being surrounded by braces on the same line.)

Anno Siegel 11-15-2004 02:44 PM

Re: A preference in the style guide
 
Arndt Jonasson <do-not-use@invalid.net> wrote in comp.lang.perl.misc:
>
> I've been reading the style guide (perldoc perlstyle), and I have
> trouble understanding one of the short preferences listed in the
> beginning:
>
> "Space after last parenthesis matching on current line."
>
> Can someone give simple examples where this preference is
> followed, and not followed, respectively?


This follows the rule:

foo(
bar( baz( 3.141)) );

There's a space before the last ")" because the matching opening "("
isn't on the same line.

Anno

Ben Morrow 11-16-2004 12:08 AM

Re: A preference in the style guide
 

Quoth anno4000@lublin.zrz.tu-berlin.de (Anno Siegel):
> Arndt Jonasson <do-not-use@invalid.net> wrote in comp.lang.perl.misc:
> >
> > I've been reading the style guide (perldoc perlstyle), and I have
> > trouble understanding one of the short preferences listed in the
> > beginning:
> >
> > "Space after last parenthesis matching on current line."
> >
> > Can someone give simple examples where this preference is
> > followed, and not followed, respectively?

>
> This follows the rule:
>
> foo(
> bar( baz( 3.141)) );
>
> There's a space before the last ")" because the matching opening "("
> isn't on the same line.


FWIW I've recently taken to invariably writing the above as

foo(
bar( baz(3.141))
);

with the closing ) lined up as though it was a brace: it uses an extra
line, but I find it much clearer. (to generalize, I would write a
compilcated if as

if (
foo && bar && baz
) {
...
}

..)

Ben

--
"The Earth is degenerating these days. Bribery and corruption abound.
Children no longer mind their parents, every man wants to write a book,
and it is evident that the end of the world is fast approaching."
-Assyrian stone tablet, c.2800 BC ben@morrow.me.uk

Anno Siegel 11-16-2004 01:56 PM

Re: A preference in the style guide
 
Ben Morrow <usenet@morrow.me.uk> wrote in comp.lang.perl.misc:
>
> Quoth anno4000@lublin.zrz.tu-berlin.de (Anno Siegel):
> > Arndt Jonasson <do-not-use@invalid.net> wrote in comp.lang.perl.misc:
> > >
> > > I've been reading the style guide (perldoc perlstyle), and I have
> > > trouble understanding one of the short preferences listed in the
> > > beginning:
> > >
> > > "Space after last parenthesis matching on current line."
> > >
> > > Can someone give simple examples where this preference is
> > > followed, and not followed, respectively?

> >
> > This follows the rule:
> >
> > foo(
> > bar( baz( 3.141)) );
> >
> > There's a space before the last ")" because the matching opening "("
> > isn't on the same line.

>
> FWIW I've recently taken to invariably writing the above as
>
> foo(
> bar( baz(3.141))
> );


That's what I do too. In fact, in such cases I would introduce parentheses
in a call I would write without if it fit on one line, so

map <short_expression>, <short_list>;

becomes

map(
<long_expression>,
<long_list>,
);

If the function has more than one argument, I add commas after all of
them, including the last one.

I'm not entirely consistent with this style, however.

map <long_expression>,
<long_list>;

is still an alternative if <long_expression> and <long_list> each fit on
one line. If they don't, it's definitely the parenthesized form.

Anno


All times are GMT. The time now is 10:57 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.