Re: Functorial interfaces

From: Date: Sun, 15 May 2016 14:45:01 +0000
Subject: Re: Functorial interfaces
References: 1 2 3 4 5 6 7  Groups: php.internals 
Request: Send a blank email to internals+get-93341@lists.php.net to get a copy of this message
2016-05-15 16:21 GMT+02:00 Rasmus Schultz <rasmus@mindplay.dk>: > > As a downside, you can't implement it in a normal class anymore and just > use > > an instance of that class. > > I see that as a plus, because, as a you said: > > > That's why you call it with the method name of the interface > > Your logic is circular - you also said: > > > As a downside, you can't implement it in a normal class anymore and just > use > > an instance of that class. > > So you want it both ways, class and callable. > > But if I'm not supposed to invoke it as a callable, why implement it > as a callable in the first place? > > In other words, you can't really have both - it doesn't really work: a > callable can be treated as a class, but a class can't be treated as > callable. If I have to treat everything as classes anyhow, why not > just use classes? > > The only advantage seems to be shorter syntax than anonymous class > declarations - the resulting objects have to be treated the same way > in practice, From the RFC: The anonymous class version: - must use referencing, or fetch a new Countable object on each iteration, - is extremely verbose - must set dependencies in the constructor - has no support for lexical scope The functional interface version: - is sparse - is easier to reason about - does not require the use of references - supports lexical scope - Functional interface support does not change the definition of an interface, and only reuse the definition of a Closure. > e.g. you can't safely treat them as callables. That's > where the chain falls off for me: you end up with callables, but you > shouldn't depend on them being callables, so then why make them > callables in the first place?

« previous php.internals (#93341) next »