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

Re: RFC-Modern OOP In Perl

Thread Previous | Thread Next
From:
Darren Duncan
Date:
January 17, 2022 10:29
Subject:
Re: RFC-Modern OOP In Perl
Message ID:
7ea8016d-8184-2f4b-37d0-a263979a6fa9@darrenduncan.net
On 2022-01-17 1:05 a.m., Ovid via perl5-porters wrote:
> On Sunday, 16 January 2022, 21:27:01 CET, Ricardo Signes <perl.p5p@rjbs.manxome.org> wrote:
>>   > The current implementation of required methods is to simply create a forward declaration: method
>>   > foo; without listing the signature. Signatures are currently not introspectable, so we cannot use them
>>   > to verify that the correct required method is present
>>   
>>   How much inspectability would you have?  Arity?  Variable name?  Requiredness of each?  Op tree of
>> defaults? :)
> 
> Is this needing an answer now? I've started to answer several times and it kept getting too long-winded and too speculative, and I'm going to do it again.

For what its worth, languages like Java and C# have a fair amount of 
introspectability of classes/routines/parameters/etc, maybe something to learn from.

> I can't easily answer that and it's going to take a lot of discussion/design. To do it properly for required methods in roles, we also need types and return values and I don't expect either of those are on the table, so we can just punt and go with arity, but that could hobble further development if we get it wrong.
> 
> But let's say we go with arity, defined as the minimum *required* number of arguments. Do we include the invocant such that no method can have an arity of zero? And is this only for introspection or do we expose it for can()?
> 
>      class Some::Class {
>          sub bar($first,$second,$third) {...}
>          method bar($baz) {...}
>      }

In the general case, the invocant object instance absolutely is a logical 
required argument.

So-called object-orientation is just syntactic sugar anyway that lets you treat 
one argument as special.  There's nothing in OO that doesn't have counterparts 
in functional languages and such.

Saying "$x->f($y)" is nothing more than syntactic sugar for "f($x,$y)".

Logically the ONLY zero-argument function is a constant definition, it always 
returns the same single value.

A common use case of these is to define the default value for a field/variable/etc.

Any method that can behave differently depending which invocant object it is 
called on must have an arity of at least 1, that being the invocant.

So you CAN have arity-zero methods, but these do NOT have any references to the 
invocant in them, so you get the same result no matter which object you call 
them on.

-- Darren Duncan

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