On Tue, 10 Mar 2020 at 15:04, Mike Schinkel <[email protected]> wrote:
> > I think he meant return type declaration. That's why the question about
> > the `use` clause is as well relevant.
>
Yes, that was a typo on my part, sorry.
> But even so, the question is surprising because we have a well established
> existing pattern with extends and implements clauses, for example:
>
> function foo():returntype
> extends Parent
> implements Interface1, Interface2, Interface2
> attributes Attribute1, Attribute2, Attribute3 {}
>
>
I'm not sure where you're going with that - as far as I know, extends and
implements are only valid on classes, and return types are only valid on
functions, so there'd never be a mixture in one declaration.
Still, you're right that it's perfectly resolvable, it's just an extra
consideration to throw into the mix.
I do think that particular syntax would get a bit messy with more involved
declarations, though:
public static function doSomething(Action $what, int $howManyTimes):
boolean attributes Memoize, Jit, Log(LogLevel::DEBUG), Autowire(1) {
// ...
}
Maybe rules for whitespace would evolve to let that flow onto multiple
lines, but it's not quite clear how the indenting should look; like this
maybe?
public static function doSomething(Action $what, int $howManyTimes):
boolean
attributes Memoize, Jit, Log(LogLevel::DEBUG), Autowire(1) {
// ...
}
The current proposed syntax leaves the main declaration as it is now, and
visually separates the attributes at the expense of vertical whitespace:
<< Memoize>>
<<Jit>>
<<Log(LogLevel::DEBUG)>>
<<Autowire(1)>>
public static function doSomething(Action $what, int $howManyTimes):
boolean {
// ...
}
A suggestion that's come up a couple of times is to allow grouping of
attributes, so you could flatten it onto one line:
<<Memoize, Jit, Log(LogLevel::DEBUG), Autowire(1)>>
public static function doSomething(Action $what, int $howManyTimes):
boolean {
// ...
}
Or the attributes could be grouped according to some coding standard:
<<Memoize, Jit>>
<<Log(LogLevel::DEBUG), Autowire(1)>>
public static function doSomething(Action $what, int $howManyTimes):
boolean {
// ...
}
There's plenty of other possibilities we could consider, though - again,
see the Python wiki link for a whole range of proposals they had for
decorators, and we may be able to find similar lists to learn from for
other languages.
Regards,
--
Rowan Tommins
[IMSoP]