Req #54243 [Sus]: Shorter syntax for closures
| From: | cmb@php.net | Date: | Fri, 17 Jun 2016 18:01:14 +0000 |
| Subject: | Req #54243 [Sus]: Shorter syntax for closures | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-201703@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=54243&edit=1
ID: 54243
Updated by: cmb@php.net
Reported by: anil at saog dot net
Summary: Shorter syntax for closures
Status: Suspended
Type: Feature/Change Request
Package: *General Issues
Operating System: *
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
Such change would require an RFC anyway. Anybody is free to write
one, see <https://wiki.php.net/rfc/howto>.
Previous Comments:
------------------------------------------------------------------------
[2012-12-03 04:01:09] id2639730 at gmail dot com
When do you plan to implement short syntax for closures?
+1 for c# lambda style.
Ecmascript 6 short function syntax used this approach. Typescript language already using lambdas.
Zend Framework 2 and Symfony2 actively using closures to work with events.
------------------------------------------------------------------------
[2012-04-11 14:55:49] johannes@php.net
One of the goals of PHP is to have a "verbose enough" syntax. Giving people ways to search
for information if they don't understand it. With the current syntax people reading the code
see the word "function" an can get an idea what this might be and have a term to put in a
search engine.
On the other side sometimes that is changed, like with arrays, initially one had to use array() to
build arrays, nowadays we have the $a = [ ]; as shortcut, so maybe we'll add a new syntax, but
only in the long run, when we see that anonymous functions really are going mainstream.
------------------------------------------------------------------------
[2012-04-11 09:38:34] ninzya at inbox dot lv
I'm sorry, Anil, but you did not convince me on readability of "Where($($a, $b,
{$a == $b}))".
"Microsoft's way" to define closures in C# linq "Where((a,b) => a ==
b)", in my
opinion, is far more readable. I read it as "a two argument function "(a,b)"
which results ("=>") in a being equal b ("a == b") or whatever the logic is
defined there. However you can not read "$($a, $b, {$a == $b})" as good as you
read microsoft's code. To me, there are too much dollar characters and they make
your eyes hurt when you try to really understand which token does the dollar
sing really belong to. You definately don't want readers of your code to
tokenize a lot when the goal is readability :-)
------------------------------------------------------------------------
[2012-03-19 11:54:13] anil at saog dot net
Guys, please calm down. I have no idea why you write these comments in a heat but this issue is just
a wishing. Also, readability is a non-objective property which generally differs person to person,
but the "key" is "shorter means readable". By the way, did you ever inspect c# -
linq syntax?
C# : ...Where((a,b) => a == b)
PHP : ...Where(function($a, $b){ return $a == $b; })
MY : ...Where($($a, $b, {$a == $b}))
readability? yes of course readability... so you think you are better than microsoft on readability?
If you do not agree of course it is okay just tell it (like a human) otherwise keep your ignoble and
invaluable ideas to yourself.
------------------------------------------------------------------------
[2012-03-19 11:13:20] ninzya at inbox dot lv
I think the proposed syntax is not readable at all. Rather it looks like you have
been affected by a "wannabe jQuery inventor". How do you come up with a dollar
sign being "readable"? How do you define "readable code"? If you read your code,
you read it as "dollar, dollar, bracket, dollar, dollar... whatever, dollar". Is
this what you call "readability"?
However I do agree that the "use()" clause of closures sometimes bloats the code a
little bit, especially if the closure is importing a lot of variables from its
context.
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=54243
--
Edit this bug report at https://bugs.php.net/bug.php?id=54243&edit=1