rfc:group_use_declarations

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:group_use_declarations [2015/02/13 17:41] – Use DokuWiki '' syntax ajfrfc:group_use_declarations [2017/09/22 13:28] (current) – external edit 127.0.0.1
Line 3: Line 3:
   * Date: 2015-01-28   * Date: 2015-01-28
   * Author: Márcio Almada, marcio.web2@gmail.com   * Author: Márcio Almada, marcio.web2@gmail.com
-  * Status: Voting (previously Under Discussion)+  * Status: Implemented (in PHP 7.0)
   * First Published at: http://wiki.php.net/rfc/group_use_declarations   * First Published at: http://wiki.php.net/rfc/group_use_declarations
   * Patch: https://github.com/php/php-src/pull/1005   * Patch: https://github.com/php/php-src/pull/1005
Line 24: Line 24:
  
 ===== Proposal ===== ===== Proposal =====
-Group use declarations are just **syntactic sugar** to cut verbosity when importing multiple entities from a common namespace. Using common PHP library examples, the following use declarations are equivalents:+Group use declarations are used to cut verbosity when importing multiple entities from a common namespace. Using common PHP library examples, the following use declarations are equivalents:
  
 <code php> <code php>
Line 125: Line 125:
 use Symfony\Component\Console\Question\{ use Symfony\Component\Console\Question\{
     ConfirmationQuestion,     ConfirmationQuestion,
-    ChoiceQuestion as Choice;+    ChoiceQuestion as Choice,
 +   OptionQuestion, +   OptionQuestion,
     Question,     Question,
Line 153: Line 153:
   * The search for literal full qualified namespaces can become less straightforward.   * The search for literal full qualified namespaces can become less straightforward.
  
-===== About The Syntax Choice =====+==== About The Syntax Choice ====
 The syntax chosen is inline with the current [[http://php.net/traits|trait adaptation]] syntax to make it look and feel similar to existing PHP standards. Such design choice allows the feature to stay familiar and intuitive to most PHP user base. The syntax chosen is inline with the current [[http://php.net/traits|trait adaptation]] syntax to make it look and feel similar to existing PHP standards. Such design choice allows the feature to stay familiar and intuitive to most PHP user base.
  
Line 173: Line 173:
  
 This shall be addressed on voting phase: should a trailing "\" be enforced or removed from syntax? This shall be addressed on voting phase: should a trailing "\" be enforced or removed from syntax?
- 
-===== Backward Incompatible Changes ===== 
-There is no BC breaks with current implementation or feature concepts. 
  
 ===== Proposed PHP Version(s) ===== ===== Proposed PHP Version(s) =====
Line 181: Line 178:
  
 ===== RFC Impact ===== ===== RFC Impact =====
 +
 +=== On Functional Programming / Autoloading ===
 +
 +Group use declarations is also very helpful for the PHP user base more fond to the **functional** programming paradigms. This RFC would be especially important if PHP finally gets **function autoloading**.
 +
 +Currently, sets of independent functions have to be implemented as static classes. But with function autoloading, they’d have to be imported independently, and that would lead to way too many use statements without this feature. Here is an example to illustrate this impact using the well known Nikita's [[https://github.com/nikic/iter|iter]] functional library:
 +
 +<code php>
 +// Current use syntax:
 +
 +use function iter\range;
 +use function iter\map;
 +use function iter\filter;
 +use function iter\apply;
 +use function iter\reduce;
 +use function iter\fn\operator;
 +
 +// Proposed syntax:
 +
 +use function iter\{ range, map, filter, apply, reduce, fn\operator };
 +
 +</code>
  
 === On Backward Compatibility === === On Backward Compatibility ===
Line 193: Line 212:
   * [[http://www.rust-lang.org|Rust Language]] has a very similar syntax ''use a::b::{c, d, e, f};''   * [[http://www.rust-lang.org|Rust Language]] has a very similar syntax ''use a::b::{c, d, e, f};''
   * [[http://www.scala-lang.org/old/node/119|Scala]] has a very similar syntax ''use a.b.{c, d, e, f};''   * [[http://www.scala-lang.org/old/node/119|Scala]] has a very similar syntax ''use a.b.{c, d, e, f};''
-  * [[https://www.python.org|Pyhon]] has a different syntax but with the same objective: ''from fibo import fib, fib2, fib3''+  * [[https://www.python.org|Python]] has a different syntax but with the same objective: ''from fibo import fib, fib2, fib3''
  
 ===== Votes ===== ===== Votes =====
 As this is a language change, this RFC requires a 2/3 majority of Yes votes (with or without trailing "\") to pass. Voting started on 2015-02-11 and will end on 2015-02-25. As this is a language change, this RFC requires a 2/3 majority of Yes votes (with or without trailing "\") to pass. Voting started on 2015-02-11 and will end on 2015-02-25.
  
-<doodle title="Should Grouped Use Declarations be added to PHP 7" auth="marcio" voteType="single" closed="false">+<doodle title="Should Grouped Use Declarations be added to PHP 7" auth="marcio" voteType="single" closed="true">
    * Yes - **with** a trailing "\"    * Yes - **with** a trailing "\"
    * Yes - **without** a trailing "\"    * Yes - **without** a trailing "\"
    * No    * No
 </doodle> </doodle>
 +
 +===== Discussion in a Nutshell =====
 +
 +In case you missed the discussion. This section lists the common counter points towards this RFC and how they were replied by the RFC author and supporters on mailing lists and media:
 +
 +==== My IDE already does the imports for me and folds the namespaces so I don't need this feature ====
 +
 +We should create **usable languages by design** rather than **languages only usable by tooling**. Tooling can be very important
 +but the moment you notice a stack of tools is needed to have a reasonable experience and readability with a programming language then something needs to be improved.
 +
 +A programming language should be able stand on its own and not require IDE assistance for reasonable use. That's what this RFC does, it brings a very common feature already available in many languages employing some kind of namespacing.
 +
 +==== The RFC encourages violation of the the SRP and other best practices ====
 +
 +This is **not true**. Nikita already wrote a great response to this on the official PHP mailing list. Beware of the slay of good argumentation ahead: http://news.php.net/php.internals/82622
 +
 +==== We should have "first class packages" first, therefore we can't approve this RFC now! ====
 +
 +This is painfully illogic. Group use declarations and "first class packages" are completely orthogonal features. Having group use declarations will only help to support long awaited features like "first class namespaces" or "function autoloading". The order in which the features are proposed or accepted is irrelevant in this case. We can **have** the feature **now**.
 +
 +Doing so **prior** to a major PHP7 **release** is, in fact, the **best hour** to **approve** this RFC.
 +
 +==== We should go for Python's syntax instead and reject this RFC ====
 +
 +I doubt Python syntax will ever be proposed for PHP because it would require the the **from** keyword to be reserved, hence one of the reasons it was discarded during research and discussion. Other reason is that the glob brace syntax is more tailored for PHP and it is a [[https://wiki.php.net/rfc/group_use_declarations#support_in_other_languages|good choice]].
 +
  
 ===== Patches and Tests ===== ===== Patches and Tests =====
Line 227: Line 272:
   - NikiC for providing accurate information about the PHP implementation.   - NikiC for providing accurate information about the PHP implementation.
   - All people on http://chat.stackoverflow.com/rooms/11/php   - All people on http://chat.stackoverflow.com/rooms/11/php
 +
rfc/group_use_declarations.1423849268.txt.gz · Last modified: 2017/09/22 13:28 (external edit)