A preference in the style guide

Discussion in 'Perl Misc' started by Arndt Jonasson, Nov 15, 2004.

  1. 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.)
     
    Arndt Jonasson, Nov 15, 2004
    #1
    1. Advertising

  2. Arndt Jonasson

    Anno Siegel Guest

    Arndt Jonasson <> 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
     
    Anno Siegel, Nov 15, 2004
    #2
    1. Advertising

  3. Arndt Jonasson

    Ben Morrow Guest

    Quoth -berlin.de (Anno Siegel):
    > Arndt Jonasson <> 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, Nov 16, 2004
    #3
  4. Arndt Jonasson

    Anno Siegel Guest

    Ben Morrow <> wrote in comp.lang.perl.misc:
    >
    > Quoth -berlin.de (Anno Siegel):
    > > Arndt Jonasson <> 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
     
    Anno Siegel, Nov 16, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Darrel
    Replies:
    3
    Views:
    689
    Kevin Spencer
    Nov 11, 2004
  2. VB Programmer

    Credit Card Gateways - Your preference?

    VB Programmer, Apr 28, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    366
    VB Programmer
    Apr 29, 2005
  3. Fran
    Replies:
    0
    Views:
    351
  4. Joe Hughes
    Replies:
    1
    Views:
    507
    Douglas Adams
    Jul 19, 2005
  5. Roland
    Replies:
    0
    Views:
    485
    Roland
    May 26, 2005
Loading...

Share This Page