Re: [RFC] Short-function syntax

From: Date: Mon, 26 Oct 2020 14:29:16 +0000
Subject: Re: [RFC] Short-function syntax
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-112124@lists.php.net to get a copy of this message
> The use of > instead of => could if possible indicate the method being void > and reduce even more: I think that for void, it could just identify it and not return nothing automatically. function a(): int => b(); // equivalents to function a(): int { return b(); } function x(): void => y(); // equivalents to function x(): void { y(); } Atenciosamente, David Rodrigues Em seg., 26 de out. de 2020 às 11:23, Michał Marcin Brzuchalski < michal.brzuchalski@gmail.com> escreveu: > Hi Larry, > > I'm wondering why we hadn't thought yet about reducing the need for $this > in this syntax. > Since arrow functions have an ability to capture variables defined in > parent scope why not > think of the same for class properties which will automatically reduce > short methods verbosity. > > class X { > public function __construct(private int $foo, private int $bar) {} > public function getFoo(): int => $foo; > public function getBar(): int => $bar; > } > > And then going further why not removing = from arrow which indicated that > there is no return value for void functions: > > class X { > public function __construct(private int $foo, private int $bar) {} > public function getFoo(): int => $foo; > public function setFoo(int $value): void > $foo = $value; > public function getBar(): int => $bar; > public function setBar(int $value): void > $bar = $value; > } > > The use of > instead of => could if possible indicate the method being void > and reduce even more: > > class X { > public function __construct(private int $foo, private int $bar) {} > public function getFoo(): int => $foo; > public function setFoo(int $value) > $foo = $value; > public function getBar(): int => $bar; > public function setBar(int $value) > $bar = $value; > } > > Would it be possible? > > If not I think we should reanimate property accessors. > > Just dropping my 50 cents. > > Best regards, > Michał Marcin Brzuchalski > > wt., 20 paź 2020 o 20:20 Larry Garfield <larry@garfieldtech.com> > napisał(a): > > > A while back, Nikita mentioned that it should now be easy to offer an > > abbreviated syntax for functions that are just a single expression. I > > decided to take a crack at it and it turns out he was right. I thus > offer > > this RFC: > > > > https://wiki.php.net/rfc/short-functions > > > > Hopefully I made a decent enough case for it. It's entirely a > convenience > > factor, but I think for many OOP cases (getter methods and factored out > > operations) and functional cases (where functions should generally be a > > single expression conceptually) it does make the code nicer, more > compact, > > and more readable. > > > > *dons flame retardant suit* > > > > -- > > Larry Garfield > > larry@garfieldtech.com > > > > -- > > PHP Internals - PHP Runtime Development Mailing List > > To unsubscribe, visit: https://www.php.net/unsub.php > > > > >

« previous php.internals (#112124) next »