Hi there,
now that syntax for variadic functions was added I quickly wanted to ask whether allowing trailing commas for function calls could be reconsidered.
It is a very small change to the language allowing something like
my_variadic_function(
"foo",
"bar",
"qux",
);
which makes adding/removing additional parameters a little easier: No comma has to be added/removed from the last line.
Previously this was considered unnecessary but maybe things changed enough to reconsider it? It doesn't involve any BC break and I attached the very simple patch needed in the master branch.
If people still consider it more harm- than useful then please don't flame me and I'll shut up again :-)
Cheers,
- Chris
diff --git a/Zend/zend_language_parser.y b/Zend/zend_language_parser.y
index 9612324..f299f3e 100644
--- a/Zend/zend_language_parser.y
+++ b/Zend/zend_language_parser.y
@@ -639,7 +639,7 @@ return_type:
argument_list:
'(' ')' { $$ = zend_ast_create_list(0, ZEND_AST_ARG_LIST); }
-
| '(' non_empty_argument_list ')' { $$ = $2; }
-
| '(' non_empty_argument_list possible_comma ')' { $$ = $2; }
;
non_empty_argument_list:
On Wed, Jun 17, 2015 at 2:05 PM, Christian Schneider cschneid@cschneid.com
wrote:
Hi there,
now that syntax for variadic functions was added I quickly wanted to ask
whether allowing trailing commas for function calls could be reconsidered.It is a very small change to the language allowing something like
my_variadic_function(
"foo",
"bar",
"qux",
);
which makes adding/removing additional parameters a little easier: No
comma has to be added/removed from the last line.Previously this was considered unnecessary but maybe things changed enough
to reconsider it? It doesn't involve any BC break and I attached the very
simple patch needed in the master branch.If people still consider it more harm- than useful then please don't flame
me and I'll shut up again :-)Cheers,
- Chris
diff --git a/Zend/zend_language_parser.y b/Zend/zend_language_parser.y
index 9612324..f299f3e 100644
--- a/Zend/zend_language_parser.y
+++ b/Zend/zend_language_parser.y
@@ -639,7 +639,7 @@ return_type:argument_list:
'(' ')' { $$ = zend_ast_create_list(0, ZEND_AST_ARG_LIST);
}
| '(' non_empty_argument_list ')' { $$ = $2; }
| '(' non_empty_argument_list possible_comma ')' { $$ = $2; }
;
non_empty_argument_list:
--
hi,
just linking to the previous rfc:
https://wiki.php.net/rfc/trailing-comma-function-args and discussion:
http://www.serverphorums.com/read.php?7,655532
--
Ferenc Kovács
@Tyr43l - http://tyrael.hu
On Wed, Jun 17, 2015 at 2:05 PM, Christian Schneider <
cschneid@cschneid.com>
wrote:Hi there,
now that syntax for variadic functions was added I quickly wanted to ask
whether allowing trailing commas for function calls could be
reconsidered.It is a very small change to the language allowing something like
my_variadic_function(
"foo",
"bar",
"qux",
);
which makes adding/removing additional parameters a little easier: No
comma has to be added/removed from the last line.Previously this was considered unnecessary but maybe things changed
enough
to reconsider it? It doesn't involve any BC break and I attached the very
simple patch needed in the master branch.If people still consider it more harm- than useful then please don't
flame
me and I'll shut up again :-)hi,
just linking to the previous rfc:
https://wiki.php.net/rfc/trailing-comma-function-args and discussion:
http://www.serverphorums.com/read.php?7,655532
I missed the vote on this one, but I'd be +1.
That said, the VCS blame issue doesn't seem strong enough for me. Just put
the comma at the front of the list item and you don't have to modify two
lines:
// initial state
$fp = fopen(
"sample.txt"
, "r+"
);
// modified state
$fp = fopen(
"sample.txt"
, "r+"
, true // only this line changed
);
I realize this may grate on styles, and it doesn't quite align with
recommendations made in canonical books like Code Complete, but it's a
decent way to get around the VCS issue and "trailing comma errors" in
syntaxes like JSON. And when you work in one language that doesn't have
the PHP nicety of trailing comma, you either adopt the lowest common
denominator (not using them) or take on the mental burden of doing both in
context (and the risk of using the trailing in unsupported contexts).
To me, the strongest argument is consistency.
Thanks,
bishop
Hi Christian,
On Wed, Jun 17, 2015 at 9:05 PM, Christian Schneider cschneid@cschneid.com
wrote:
Hi there,
now that syntax for variadic functions was added I quickly wanted to ask
whether allowing trailing commas for function calls could be reconsidered.It is a very small change to the language allowing something like
my_variadic_function(
"foo",
"bar",
"qux",
);
which makes adding/removing additional parameters a little easier: No
comma has to be added/removed from the last line.Previously this was considered unnecessary but maybe things changed enough
to reconsider it? It doesn't involve any BC break and I attached the very
simple patch needed in the master branch.If people still consider it more harm- than useful then please don't flame
me and I'll shut up again :-)
PHP allows
array(
1,
2,
3,
);
therefore
my_variadic_function(
"foo",
"bar",
"qux",
);
is consistent behavior to me.
Regards,
--
Yasuo Ohgaki
yohgaki@ohgaki.net
If people still consider it more harm- than useful then please don't flame
me and I'll shut up again :-)PHP allows
array(
1,
2,
3,
);therefore
my_variadic_function(
"foo",
"bar",
"qux",
);is consistent behavior to me.
If variadic functions allow this and normal functions don't (and by most
PHP coding standards you'll format like this all the time because of 80
chars limit I don't see how this is in any way consistent. It's still a
function call after all and not an array.
~Florian
+1 for allowing trailing comma in every function call.
Regards,
Kubo2
2015-06-18 19:16 GMT+02:00 Florian Anderiasch ml@anderiasch.de:
If people still consider it more harm- than useful then please don't flame
me and I'll shut up again :-)PHP allows
array(
1,
2,
3,
);therefore
my_variadic_function(
"foo",
"bar",
"qux",
);is consistent behavior to me.
If variadic functions allow this and normal functions don't (and by most
PHP coding standards you'll format like this all the time because of 80
chars limit I don't see how this is in any way consistent. It's still a
function call after all and not an array.~Florian
Some more context:
https://bugs.php.net/bug.php?id=64176 https://bugs.php.net/bug.php?id=64176
https://wiki.php.net/rfc/trailing-comma-function-args https://wiki.php.net/rfc/trailing-comma-function-args (failed 15-20)
On a more positive side, this change was very well received within Facebook when implemented within HHVM; this was a mix of:
- the ‘git blame’ advantage is much bigger than we expected; this is probably true for any large project that has many contributors to the same file. It doesn’t help much if each file basically has an ‘owner’.
- people new to PHP liked not having to remember where they are allowed and when they’re not. This felt like removing one small inconsistency without much of a downside
+1 for allowing trailing comma in every function call.
Regards,
Kubo22015-06-18 19:16 GMT+02:00 Florian Anderiasch ml@anderiasch.de:
If people still consider it more harm- than useful then please don't flame
me and I'll shut up again :-)PHP allows
array(
1,
2,
3,
);therefore
my_variadic_function(
"foo",
"bar",
"qux",
);is consistent behavior to me.
If variadic functions allow this and normal functions don't (and by most
PHP coding standards you'll format like this all the time because of 80
chars limit I don't see how this is in any way consistent. It's still a
function call after all and not an array.~Florian