Edit report at https://bugs.php.net/bug.php?id=54243&edit=1
ID: 54243 Updated by: johan...@php.net Reported by: anil at saog dot net Summary: Shorter syntax for closures -Status: Open +Status: Suspended Type: Feature/Change Request Package: *General Issues Operating System: * PHP Version: Irrelevant Block user comment: N Private report: N New Comment: 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. Previous Comments: ------------------------------------------------------------------------ [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. ------------------------------------------------------------------------ [2012-03-19 09:08:09] danko at very dot lv Um, no, *that* is unreadable. The original syntax can easily be made readable if you do care: $myObject->MyMethod( 'abc', function ($a) use ($b) { return $a == $b; } ); There you go. As readable as it gets - just add some newlines and tabs. On the other hand, a soup of brackets and dollar signs can't be readable regardless of formatting. ------------------------------------------------------------------------ [2011-03-13 16:16:45] anil at saog dot net Changed package ------------------------------------------------------------------------ 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