rfc:batch_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 revisionBoth sides next revision
rfc:batch_use_declarations [2015/01/29 16:31] – fix some code samples that had duplicated use statements marciorfc:batch_use_declarations [2015/01/29 22:51] – accept Danack's suggestions marcio
Line 78: Line 78:
  
 use function foo\math\sin, foo\math\cos, foo\math\cosh; use function foo\math\sin, foo\math\cos, foo\math\cosh;
-use const    foo\math\PI, foo\math\E, foo\math\GAMMA, foo\math\GOLDEN_RATIO;+use const foo\math\PI, foo\math\E, foo\math\GAMMA, foo\math\GOLDEN_RATIO;
  
 // Proposed non mixed batch use syntax: // Proposed non mixed batch use syntax:
  
 use function foo\math { sin, cos, cosh }; use function foo\math { sin, cos, cosh };
-use const    foo\math { PI, E, GAMMA, GOLDEN_RATIO };+use const foo\math { PI, E, GAMMA, GOLDEN_RATIO };
 </code> </code>
  
 === Mixed Use Declarations === === Mixed Use Declarations ===
-Current namespace implementation does not allow mixed imports of functions, constants and classes. With the approval of this RFC, for completeness, the following hypothetical mixed imports would be possible:+ 
 +The current implementation of namespaces does not allow mixed imports of functions, constants and classes. The proposed implementation would allow mixed imports like this
 + 
 +Current namespace implementation does not allow mixed imports of functions, constants and classes. The proposed implementation would allow mixed imports like this:
  
 <code php> <code php>
 // Current use syntax: // Current use syntax:
  
-use          foo\math\Math; +use foo\math\Math; 
-use const    foo\math\PI;+use const foo\math\PI;
 use function foo\math\sin, foo\math\cos, foo\math\cosh; use function foo\math\sin, foo\math\cos, foo\math\cosh;
  
Line 102: Line 105:
 </code> </code>
  
-===== About The Syntax Choice ===== +===== Justification =====
-The current choice for batch use syntax is basically a small variation from the current trait adaptation syntax:+
  
-<code php+Batch use statements makes it easier to identify that multiple imported entities are from the same module. For the first example in this RFC, instead of having to read 'FooLibrary\Bar\Baz\Biz' four times to see that the namespace is the same for each entry, it is clear by the grouping syntax that the entries all come from the same namespace. 
-use A, B { + 
-    B::smallTalk insteadof A+Also, batch use statements makes it easier to see in patch diffs that a dependency on a new module has been introduced. For instance, a patch that adds a new dependency on "Consolidation" namespace has been introduced: 
-    A::bigTalk insteadof B+ 
-}+<code> 
 +use Symfony\Component\Console\Question\ConfirmationQuestion; 
 +use Symfony\Component\Console\Question\ChoiceQuestion as Choice
 ++use Symfony\Component\Console\Question\OptionQuestion
 ++use Symfony\Component\Consolidation\Question\OptionQuestion; 
 +use Symfony\Component\Console\Question\Question;
 </code> </code>
 +
 +With the current use syntax it's necessary to read to the 30th character of the 2nd modified line to realise that the patch adds a new dependency. The proposed syntax is much more readable:
 +
 +<code>
 +use Symfony\Component\Console\Question {
 +    ConfirmationQuestion,
 +    ChoiceQuestion as Choice;
 ++   OptionQuestion,
 +    Question,
 +};
 ++use Symfony\Component\Consolidation\Question\OptionQuestion;
 +</code>
 +
 +
 +===== About The Syntax Choice =====
 +The syntax chosen is inline with the current 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. Such design choice allows the feature to stay familiar and intuitive to most PHP user base.
rfc/batch_use_declarations.txt · Last modified: 2017/09/22 13:28 by 127.0.0.1