develooper Front page | perl.perl5.porters | Postings from January 2022

Re: Things you can't do in a signatured sub

Thread Previous | Thread Next
From:
Paul "LeoNerd" Evans
Date:
January 24, 2022 19:22
Subject:
Re: Things you can't do in a signatured sub
Message ID:
20220124192232.42bb5524@shy.leonerd.org.uk
On Mon, 24 Jan 2022 16:54:16 +0000 (UTC)
Ovid <curtis_ovid_poe@yahoo.com> wrote:

> As an aside, but something we might want to keep in mind for future
> work, many languages simply don't have this issue because of method
> overloading:
...
> Allowing this in Perl would be a win because, IMHO, it's easier to
> read and matches existing, well-known conventions in other languages:
> 
>     method name () { return $name }
>     # or method name :multi () { return $name }
>     method name ( $new_name ) { $name = $new_name }
>     # or method name :multi ( $new_name ) { $name = $new_name }

You mean like

  use v5.26;
  use Syntax::Keyword::MultiSub;
  use experimental 'signatures';
 
  multi sub max()          { return undef; }
  multi sub max($x)        { return $x; }
  multi sub max($x, @more) { my $y = max(@more);
                             return $x > $y ? $x : $y; }

   -- https://metacpan.org/pod/Syntax::Keyword::MultiSub

Doesn't yet support `multi method ...` but I keep meaning to get around
to starting implementing that.

> No, I'm not suggesting we do that, 

Oh, I am ;)

> but this is (to me) much easier to
> follow. If types get incorporated at some point in the future, I have
> a ton of code that could be simplified by dispatching on type rather
> than if/else blocks. Overloading methods/subs allows us to have
> logically separated blocks of code for logically separate things.
> 
> Again, this is not a suggestion or a recommendation, but something to
> keep in mind. I'm happy to see signatures get out the door in their
> current state.

Yup - that's part of my grand design for 2025 - obligatory link to

  https://archive.fosdem.org/2021/schedule/event/perl_in_2025/

-- 
Paul "LeoNerd" Evans

leonerd@leonerd.org.uk      |  https://metacpan.org/author/PEVANS
http://www.leonerd.org.uk/  |  https://www.tindie.com/stores/leonerd/

Thread Previous | 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