rfc:any_all_on_iterable_straw_poll_namespace

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
rfc:any_all_on_iterable_straw_poll_namespace [2021/01/17 13:51] tandrerfc:any_all_on_iterable_straw_poll_namespace [2021/02/03 00:30] (current) tandre
Line 1: Line 1:
 ====== Straw poll: Using namespaces for *any() and *all() on iterables ====== ====== Straw poll: Using namespaces for *any() and *all() on iterables ======
-  * Version: 0.1+  * Version: 0.2
   * Date: 2021-01-05   * Date: 2021-01-05
   * Author: Tyson Andre, tandre@php.net   * Author: Tyson Andre, tandre@php.net
-  * Status: Under Discussion+  * Status: Closed
   * First Published at: http://wiki.php.net/rfc/any_all_on_iterable_straw_poll_namespace   * First Published at: http://wiki.php.net/rfc/any_all_on_iterable_straw_poll_namespace
  
Line 22: Line 22:
   - I plan to propose additional internal functions for working with iterables if this succeeds, and would want to be sure this is the best name choice going forwards.   - I plan to propose additional internal functions for working with iterables if this succeeds, and would want to be sure this is the best name choice going forwards.
   - Additionally, this has been an opportunity for measuring overall interest in adopting namespaces for brand new categories of functionality - existing methods work on Traversables (''iterator_*'') or arrays (''array_*''), but generally not both.   - Additionally, this has been an opportunity for measuring overall interest in adopting namespaces for brand new categories of functionality - existing methods work on Traversables (''iterator_*'') or arrays (''array_*''), but generally not both.
 +
 +===== Discussion =====
 +
 +==== Arguments for voting again on namespaces ====
  
 https://externals.io/message/112558 https://externals.io/message/112558
Line 65: Line 69:
 </blockquote> </blockquote>
  
-===== Discussion ===== 
  
-==== Choice of namespace ====+==== Arguments for Spl\ ====
  
 This poll includes one of the naming options suggested by Levi Morrison and uses the suggested namespace for alternative options. This poll includes one of the naming options suggested by Levi Morrison and uses the suggested namespace for alternative options.
Line 89: Line 92:
   - The ''Spl\'' namespace can be reused for new classes/functions if they belong in the ''spl'' module. (I have no plans to move existing functions/classes to that namespace)   - The ''Spl\'' namespace can be reused for new classes/functions if they belong in the ''spl'' module. (I have no plans to move existing functions/classes to that namespace)
  
-==== Future extension ====+https://externals.io/message/112558#112834
  
-It is possibly that functionality to check if any/all keys satisfy a predicate, or any/all combinations of entries add a predicate. +<blockquote> 
-If this gets added, there are two possibilities+From Levi Morrison:
  
-  - Add ''*any_key'' for keys, and ''*any_entry''/''*any_key_value()'' for key+value combination +I want to make a case for `Spl`. Aside from autoloading (which really 
-  - Add flags to the ''*any()'' method, like ''array_filter()''+ought to be in core but since "spl" is literally in the name of those 
 +functions it's kind of stuck), the SPL is mostly data structures and 
 +iterator related functionality. It makes perfect sense to me that 
 +iterator related behavior like these iterable functions being proposed 
 +should be included in the SPL. The `Spl` namespace is short, and its 
 +brevity doesn't lose any meaning because the SPL has been around in 
 +core since PHP 5.3 (I think?).
  
-There's precedent for both choices of naming patterns, and I'm fine with either choicePrecedents include array_values() and array_keys(), as well as array_diff() and array_diff_keys()+...
  
-==== Inconveniences of iterable\ in namespace ====+One of the arguments against using the SPL is that much of its 
 +existing design is... well, weird and sub-optimal in many cases. At 
 +least a few people recommend against using SPL data structures and 
 +iterators because of this. However, I think the `Spl` namespace can 
 +separate these well enough. 
 +</blockquote>
  
-From https://externals.io/message/112558#112832+==== Arguments for PHP\ ====
  
 +https://www.php.net/manual/en/language.namespaces.rationale.php reserved the uppercase namespace PHP\ for internal use.
 +
 +https://wiki.php.net/rfc/php_namespace_policy was an earlier (declined) proposal that had suggested the use of PHP\SubNS for internal features.
 +
 +https://externals.io/message/112558#112841
 <blockquote> <blockquote>
-I've also realized that use prefix\iterable would be mildly inconvenient for users of PHP and for tooling (refactoring tools, IDEs, etc) for PHP, +FWIW as iterables and the likes relate to engine features, the PHP 
-but still include it as an option because it'manageable and the non-namespaced prefix iterable_ was preferred in the previous poll.+namespace policy RFC would have considered them ideal candidates for 
 +\PHP\SubNS rather than \Ext\SubNS 
 + 
 +Mark Randall 
 +</blockquote> 
 + 
 +From Nikita Popov: https://externals.io/message/112558#112780 
 + 
 +<blockquote> 
 +Using just the SPL namespace (that is, SPL\any) makes the SPL namespace a 
 +dumping ground for everything, as you said. Once you introduce an 
 +additional meaningful namespace in the form of SPL\iterable\any, you are 
 +better off either dropping the SPL part and arriving at iterable\any, or 
 +replacing SPL with something more sensible and arriving at PHP\iterable\any. 
 +</blockquote> 
 + 
 +==== Arguments for/against iterable\ in namespace ==== 
 + 
 +https://externals.io/message/112558#112773 
 + 
 +<blockquote> 
 +I'm happy to have these functions namespaced, but I'm not sure the 
 +suggestion to namespace them under Spl makes sense. This functionality has 
 +fairly little to do with the SPL as it is now and to be honest, by now 
 +there is quite a bit of ... stigma associated with functionality that 
 +resides in SPL. 
 + 
 +I would suggest using iterable\any and iterable\all as the names if we want 
 +to go down this route. iterable_any and iterable_all were the by far most 
 +popular choices on the previous poll, and these are just the namespaced 
 +variants thereof. 
 + 
 +Regards, 
 +Nikita 
 +</blockquote> 
 + 
 +From https://externals.io/message/112558#112832 
 + 
 +I've also realized that ''use prefix\iterable'' would be mildly inconvenient for users of PHP and for tooling (refactoring tools, IDEs, etc) for PHP, 
 +but still include it as an option because it'**unlikely to be a problem in practice  and the non-namespaced prefix iterable_ was preferred in the previous poll.**
  
 <code php> <code php>
-php > namespace { echo iterable::class; } +php > namespace iterable { function my_any(...$args) {echo "in my_any() polyfill\n";}
-W\iterable+php > \iterable\my_any(); // can be called with the fully qualified name 
 +in my_any() polyfill 
 +php > namespace X { use iterable\my_any; my_any(); /* using individual functions works and is how namespaced functions are often used */ } 
 +in my_any() polyfill 
 +php > namespace { iterable\my_any();
 +in my_any() polyfill
  
 +
 +
 +php > namespace W { echo iterable::class; /* Edge cases that should not be a problem in practice, but mentioned for completeness */ }
 +W\iterable
 php > namespace X { use iterable; } php > namespace X { use iterable; }
  
 Fatal error: Cannot use iterable as iterable because 'iterable' is a special class name in php shell code on line 1 Fatal error: Cannot use iterable as iterable because 'iterable' is a special class name in php shell code on line 1
-php > namespace X { use iterable\any; /* using individual functions works */ } +php > namespace X { use PHP\iterable; }
-php > namespace Y { use PHP\iterable; function foo(iterable $x) {}}+
  
 Fatal error: Cannot use PHP\iterable as iterable because 'iterable' is a special class name in php shell code on line 1 Fatal error: Cannot use PHP\iterable as iterable because 'iterable' is a special class name in php shell code on line 1
-php > namespace { use PHP\iterable as iter; + 
-php > namespace iterable { echo "can be polyfilled\n"; } +php > namespace { use iterable as iter; iter\my_any(); } 
-can be polyfilled+in my_any() polyfill
 </code> </code>
-</blockquote> 
  
 ===== Vote ===== ===== Vote =====
 +
 +Voting started on 2021-01-19 and ended on 2021-02-02. Of the top two options, 12 voters had ranked "PHP\iterable" before the global namespace (including not listing the latter in their vote). 11 voters had ranked the global namespace ahead of "PHP\iterable" (including not listing the latter in the vote). One voter had ranked neither option.
  
 This vote will influence the name choice for the RFC https://wiki.php.net/rfc/any_all_on_iterable This vote will influence the name choice for the RFC https://wiki.php.net/rfc/any_all_on_iterable
Line 132: Line 199:
 With STV you SHOULD rank all the choices in order (but are not required to). Don't pick the same option more than once, as that invalidates your vote. With STV you SHOULD rank all the choices in order (but are not required to). Don't pick the same option more than once, as that invalidates your vote.
  
 +**Clicking on vote will only submit your vote for the above question, not for all of them.** You may want to write down your choices to avoid losing track of them. To quickly return to the vote section, click on "Vote" in the Table of Contents on the right.
  
 +  * no namespace: iterable_any()/iterable_all()
 +  * iter\ (conflicts with [[https://github.com/nikic/iter|nikic/iter]] but was among Nikita's suggestions)
 +  * iterable\ (see [[#arguments_foragainst_iterable_in_namespace|section on iterable\ ]] , also suggested by Nikita)
 +  * PHP\ (see [[#arguments_for_php|Arguments for PHP\]])
 +  * PHP\Spl\ (see [[#arguments_for_php|Arguments for PHP\]])
 +  * PHP\iter\ (see [[#arguments_for_php|Arguments for PHP\]])
 +  * PHP\iterable\ (see [[#arguments_for_php|Arguments for PHP\]])
 +  * Ext\Spl, as one interpretation of https://wiki.php.net/rfc/php_namespace_policy . Also see [[#arguments_for_php|Arguments for PHP\]] for PHP\Spl since this the new functions would be built in.
 +  * Spl\ (see [[#arguments_for_spl|Arguments for Spl\ ]] - suggested by Levi Morrison)
 +  * Spl\iter\
 +  * Spl\iterable\ 
 +
 +
 +First choice:
 <doodle title="Straw poll: Favorite choice of namespace" auth="tandre" voteType="single" closed="true"> <doodle title="Straw poll: Favorite choice of namespace" auth="tandre" voteType="single" closed="true">
    * iterable_any() and iterable_all()    * iterable_any() and iterable_all()
Line 138: Line 220:
    * iterable\    * iterable\
    * PHP\    * PHP\
 +   * PHP\Spl\
    * PHP\iter\    * PHP\iter\
    * PHP\iterable\    * PHP\iterable\
Line 146: Line 229:
 </doodle> </doodle>
  
-<doodle title="Straw poll: Favorite choice of namespace" auth="tandre" voteType="single" closed="true">+Second choice: 
 + 
 +<doodle title="Straw poll: Second favorite choice of namespace" auth="tandre" voteType="single" closed="true">
    * iterable_any() and iterable_all()    * iterable_any() and iterable_all()
    * iter\    * iter\
    * iterable\    * iterable\
    * PHP\    * PHP\
 +   * PHP\Spl\
    * PHP\iter\    * PHP\iter\
    * PHP\iterable\    * PHP\iterable\
Line 159: Line 245:
 </doodle> </doodle>
  
-<doodle title="Straw poll: Second favorite choice of namespace" auth="tandre" voteType="single" closed="true">+Third choice: 
 + 
 +<doodle title="Straw poll: Third favorite choice of namespace" auth="tandre" voteType="single" closed="true">
    * iterable_any() and iterable_all()    * iterable_any() and iterable_all()
    * iter\    * iter\
    * iterable\    * iterable\
    * PHP\    * PHP\
 +   * PHP\Spl\
    * PHP\iter\    * PHP\iter\
    * PHP\iterable\    * PHP\iterable\
Line 172: Line 261:
 </doodle> </doodle>
  
-<doodle title="Straw poll: Third favorite choice of namespace" auth="tandre" voteType="single" closed="true">+Fourth choice: 
 + 
 +<doodle title="Straw poll: Fourth favorite choice of namespace" auth="tandre" voteType="single" closed="true">
    * iterable_any() and iterable_all()    * iterable_any() and iterable_all()
    * iter\    * iter\
    * iterable\    * iterable\
    * PHP\    * PHP\
 +   * PHP\Spl\
    * PHP\iter\    * PHP\iter\
    * PHP\iterable\    * PHP\iterable\
Line 185: Line 277:
 </doodle> </doodle>
  
-<doodle title="Straw poll: Fourth favorite choice of namespace" auth="tandre" voteType="single" closed="true">+Fifth choice: 
 + 
 +<doodle title="Straw poll: Fifth favorite choice of namespace" auth="tandre" voteType="single" closed="true">
    * iterable_any() and iterable_all()    * iterable_any() and iterable_all()
    * iter\    * iter\
    * iterable\    * iterable\
    * PHP\    * PHP\
 +   * PHP\Spl\
    * PHP\iter\    * PHP\iter\
    * PHP\iterable\    * PHP\iterable\
Line 198: Line 293:
 </doodle> </doodle>
  
-<doodle title="Straw poll: Fifth favorite choice of namespace" auth="tandre" voteType="single" closed="true">+Sixth choice: 
 + 
 +<doodle title="Straw poll: Sixth favorite choice of namespace" auth="tandre" voteType="single" closed="true">
    * iterable_any() and iterable_all()    * iterable_any() and iterable_all()
    * iter\    * iter\
    * iterable\    * iterable\
    * PHP\    * PHP\
 +   * PHP\Spl\
    * PHP\iter\    * PHP\iter\
    * PHP\iterable\    * PHP\iterable\
Line 211: Line 309:
 </doodle> </doodle>
  
-<doodle title="Straw poll: Sixth favorite choice of namespace" auth="tandre" voteType="single" closed="true">+Seventh choice: 
 + 
 +<doodle title="Straw poll: Seventh favorite choice of namespace" auth="tandre" voteType="single" closed="true">
    * iterable_any() and iterable_all()    * iterable_any() and iterable_all()
    * iter\    * iter\
    * iterable\    * iterable\
    * PHP\    * PHP\
 +   * PHP\Spl\
    * PHP\iter\    * PHP\iter\
    * PHP\iterable\    * PHP\iterable\
Line 224: Line 325:
 </doodle> </doodle>
  
-<doodle title="Straw poll: Seventh favorite choice of namespace" auth="tandre" voteType="single" closed="true">+Eighth choice: 
 + 
 +<doodle title="Straw poll: Eighth favorite choice of namespace" auth="tandre" voteType="single" closed="true">
    * iterable_any() and iterable_all()    * iterable_any() and iterable_all()
    * iter\    * iter\
    * iterable\    * iterable\
    * PHP\    * PHP\
 +   * PHP\Spl\
    * PHP\iter\    * PHP\iter\
    * PHP\iterable\    * PHP\iterable\
Line 237: Line 341:
 </doodle> </doodle>
  
-<doodle title="Straw poll: Eighth favorite choice of namespace" auth="tandre" voteType="single" closed="true">+Ninth choice: 
 + 
 +<doodle title="Straw poll: Ninth favorite choice of namespace" auth="tandre" voteType="single" closed="true">
    * iterable_any() and iterable_all()    * iterable_any() and iterable_all()
    * iter\    * iter\
    * iterable\    * iterable\
    * PHP\    * PHP\
 +   * PHP\Spl\
    * PHP\iter\    * PHP\iter\
    * PHP\iterable\    * PHP\iterable\
Line 250: Line 357:
 </doodle> </doodle>
  
-<doodle title="Straw poll: Ninth favorite choice of namespace" auth="tandre" voteType="single" closed="true">+Tenth choice: 
 + 
 +<doodle title="Straw poll: Tenth favorite choice of namespace" auth="tandre" voteType="single" closed="true">
    * iterable_any() and iterable_all()    * iterable_any() and iterable_all()
    * iter\    * iter\
    * iterable\    * iterable\
    * PHP\    * PHP\
 +   * PHP\Spl\
    * PHP\iter\    * PHP\iter\
    * PHP\iterable\    * PHP\iterable\
Line 262: Line 372:
    * Spl\iterable\    * Spl\iterable\
 </doodle> </doodle>
 +Eleventh choice:
  
-<doodle title="Straw poll: Tenth favorite choice of namespace" auth="tandre" voteType="single" closed="true">+<doodle title="Straw poll: Eleventh favorite choice of namespace" auth="tandre" voteType="single" closed="true">
    * iterable_any() and iterable_all()    * iterable_any() and iterable_all()
    * iter\    * iter\
    * iterable\    * iterable\
    * PHP\    * PHP\
 +   * PHP\Spl\
    * PHP\iter\    * PHP\iter\
    * PHP\iterable\    * PHP\iterable\
Line 275: Line 387:
    * Spl\iterable\    * Spl\iterable\
 </doodle> </doodle>
- 
 ===== What the functions do ===== ===== What the functions do =====
  
Line 301: Line 412:
 }; };
 </code> </code>
 +
 +===== Future extension of any/all =====
 +
 +It is possible that functionality to check if any/all keys satisfy a predicate, or any/all combinations of entries add a predicate.
 +If this gets added, there are two possibilities
 +
 +  - Add ''*any_key'' for keys, and ''*any_entry''/''*any_key_value()'' for key+value combination
 +  - Add flags to the ''*any()'' method, like ''array_filter()''
 +
 +There's precedent for both choices of naming patterns, and I'm fine with either choice. Precedents include array_values() and array_keys(), as well as array_diff() and array_diff_keys().
 +
  
 ===== Rejected Choices ===== ===== Rejected Choices =====
Line 331: Line 453:
   - https://github.com/php/php-src/pull/6053   - https://github.com/php/php-src/pull/6053
  
 +===== Changelog =====
 +
 +0.2: Switch to a vote on multiple namespaces
rfc/any_all_on_iterable_straw_poll_namespace.1610891472.txt.gz · Last modified: 2021/01/17 13:51 by tandre