Hi, Internals,
---- En dom, 17 may 2020 06:33:51 +0200 Peter Stalman <sarke...@gmail.com> escribió ---- > A few thoughts: > > > 1. I agree with the sentiment that this syntactic sugar doesn't > actually save any verbosity, so it's not really syntactic sugar at > all. > > > 2. There appears to now be another RFC by Pavel Patapau, specifically > focused on a Guard statement as a new keyword > (https://wiki.php.net/rfc/guard_statement), which now has its separate > discussion. > > > 3. As Thomas Lamy mentioned, I too would prefer a single keyword. > Consider the following two examples: > > function foo($bar) > { > if ($bar === 1) > return; > > if ($bar === 666) > delete_everything(); > } > > function foo($bar) > { > if ($bar === 1) > return > > if ($bar === 666); > delete_everything(); > } > > Both would now be valid syntax, and IDEs would have a harder time > warning about the misplaced semicolon in the second example. Wouldn't > be very common, but still. > > > 4. However, this RFC is interesting to me because there be a way to > modify it to allow for less verbose refactoring, and kinda allowing > returns to bubble up like exceptions do. I think it would only make > sense if it's a "if not null then return" type of thing. > > Consider the following (a bit contrived, but I hope you get the point): > > function main_function() > { > $result = calculate($var); > if ($result !== null) > return $result; > > /* do other important stuff */ > } > > function main_function() > { > ifnotnullreturn calculate($var); > > /* do other important stuff */ > } > > Obviously not an ideal keyword, but this is the only thing I can think > of where this type of syntactic sugar makes sense and decreases > verbosity. Something similar can also be accomplished with exception > though. > > > 5. Finally, I think if we start putting several returns at the same > indentation then the cognitive load increases because we can no longer > tell if a return is actually a return at a glance. > > > Thanks, > Peter > I agree. ¿ Maybe something like... function main_function() { escape when( calculate($var) ); /* do other important stuff */ } `escape when( expr )` returns value of `expr` to caller function when `expr` evaluate to true otherwise next line. function main_function() { escape with $ a + 1 when( !calculate($var) ); /* do other important stuff */ } `escape with expr1 when( expr2 )` returns value of `expr1` to caller function when `expr2` evaluate to true otherwise next line. Regards -- Manuel Canga -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php