develooper Front page | perl.perl6.language | Postings from March 2005

Comma in (sub) traits?

Thread Next
From:
wolverian
Date:
March 7, 2005 04:19
Subject:
Comma in (sub) traits?
Message ID:
20050307105549.GA15931@sci.fi
Hello all,

while writing some experimental code with Pugs, I realised that it is a
bit hard for me to parse the following type of declaration:

    sub greeting (Str $person) returns Str is export {
        "Hello, $person"
    }

Specifically, the 'is export' trait is too buried. Reformatting it like
this helps:

    sub greeting (Str $person)
        returns Str is export {
        "Hello, $person"
    }

But I really do not like the vertical alignment of the traits and the
body of the sub. So we're back to the first situation. We could also put
the 'returns' on the first line, after the signature (and strictly
speaking it at least can be a part of the signature), and the traits on
successive lines after that, but the alignment problems kicks in again.

There are other ways to format the declaration, like indenting the
traits line:

    sub greeting (Str $person) returns Str
            is export {
        "Hello, $person"
    }

This looks distinctly odd to me, although I think it works better than
the aligned version. Moving the traits line to column 0 is even weirder.

I think it is clear that I do not want to put the { on its own line. :)

The problem can be alleviated a bit by giving each trait a more
separable visual identity:

    sub greeting (Str $person) returns Str, is export {
        "Hello, $person"
    }

The above works better for me than either of the previous examples. So
my question is: can this be legal Perl 6 code (and will it DWIM)? There
are ways to format this I didn't think of, I'm sure, so I'd like to know
too what the recommended style is. (perl6doc perlstyle...)

This same problem (well, it is a problem to me) applies to other places
where traits are used as well, but I'm specifically asking in the
context of named subroutine declarations, since parsing the comma seems
at least possible there. The visual distinction in a regular 'my'
declaration brought by the comma might also look too much like a list.
(It probably is a list.)

Sorry if this has been discussed before, or even in the design
documents. I'm also sorry if this is too rambling for the list. It's not
that important, just a thought.

Cheers,
wolverian

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About