Skip Menu |
 

This queue is for tickets about the Method-Signatures CPAN distribution.

Report information
The Basics
Id: 93335
Status: open
Priority: 0/
Queue: Method-Signatures

People
Owner: Nobody in particular
Requestors: perl [...] toby.ink
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: (no value)
Fixed in: (no value)



Subject: Wishlist for Perl 5.20 signature compatibility: document that a trailing equals sign works
Download (untitled) / with headers
text/plain 296b
This already appears to work in Method::Signatures, but I can't seem to find where it's documented: method foo ($x=) { ... } method bar (@y=) { ... } That is, in a default, if `EXPR` is omitted, then `EXPR` the default is `()` - i.e. undef for scalars, and the empty list for non-scalars.
Download (untitled) / with headers
text/plain 685b
Show quoted text
> This already appears to work in Method::Signatures, but I can't seem > to find where it's documented: > > method foo ($x=) { ... } > method bar (@y=) { ... } > > That is, in a default, if `EXPR` is omitted, then `EXPR` the default > is `()` - i.e. undef for scalars, and the empty list for non-scalars.
It _isn't_ documented, because, if it's working, it's working by accident. :-/ Can't say I'm that fond of it, overall ... is this official syntax from somewhere else? I don't necessarily propose that we specifically disallow it if it's working now, but I don't know that I want to bless it officially by adding POD for it either. Perhaps an outside source would sway me. :-)
Download (untitled) / with headers
text/plain 341b
I can't say I'm massively fond of it either. It has no parallel in existing Perl 5 code. You can't for example do: my $foo = ; But this is documented syntax for Perl 5.19.9. http://search.cpan.org/~tonyc/perl-5.19.9/pod/perlsub.pod#Signatures includes the following code sample: sub foo ($thing, $=) { print $thing; }
At first I was like "no no no, that's just turning a user mistake into syntax" and now I'm like "hey, that's a really intuitive way to declare an optional variable without needing extra syntax".

My thinking goes like this.  Variables should be required by default (I hope 5.20 does this).  Optional variables should have defaults, so why not make the syntax for declaring something optional to be the same as declaring a default?

PRESTO!  No more need for the extra $foo? syntax.  One less bit of special syntax for users to remember.  And it forces the function author to think "hey, this argument should have a default".

As to the argument that there's no precedent for '$foo=' in Perl, there's a lot more precedent than '$foo?'.

My only concern is that a signature like '$foo=, $bar=' might be harder to parse... but it seems it already works so whatever.

Take this all with a grain of salt as I haven't looked at Method::Signatures, 5.20 signatures or Perl in general in months.
Download (untitled) / with headers
text/plain 1.8k
Show quoted text
> I can't say I'm massively fond of it either. It has no parallel in > existing Perl 5 code. You can't for example do: > > my $foo = ; > > But this is documented syntax for Perl 5.19.9.
Yes, all properly documented and official-looking, but that doesn't keep it from being any less STUPID. :-/ Show quoted text
> At first I was like "no no no, that's just turning a user mistake into > syntax" > and now I'm like "hey, that's a really intuitive way to declare an > optional > variable without needing extra syntax". > > My thinking goes like this. Variables should be required by default (I > hope > 5.20 does this). Optional variables should have defaults, so why not > make the > syntax for declaring something optional to be the same as declaring a > default? > > PRESTO! No more need for the extra $foo? syntax. One less bit of > special syntax > for users to remember. And it forces the function author to think > "hey, this > argument should have a default".
I remain unswayed. :-/ `$foo=` just looks stupid. If you really don't like the `$foo?` syntax, you're perfectly free to write `$foo = undef`, which is a) legal, b) obvious, and c) already working in all signature implementations. The only downside is, it's (at least) 5 more characters than `?`. Show quoted text
> As to the argument that there's no precedent for '$foo=' in Perl, > there's a lot > more precedent than '$foo?'.
I disagree, since I consider Perl 6 to be Perl (even though I know that's not always a popular viewpoint). My main point is, the very first time I ever saw `$foo?` (which was in a Perl 6 something-or-other--most likely either Apocalypse or Exegesis), I knew exactly what it meant. The first time I saw `$foo=` I thought: WTF is that abomination?? I'm just sayin'. ;-> Anyhow, all we're quibbling about is whether to document it or not, and I can't realistically mount much of a defense against doing so, I suppose. But let me sulk on it for a bit longer. :-D


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.