rfc:batch_use_declarations
Differences
This shows you the differences between two versions of the page.
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 marcio | rfc:batch_use_declarations [2015/01/29 22:51] – accept Danack's suggestions marcio | ||
---|---|---|---|
Line 78: | Line 78: | ||
use function foo\math\sin, | use function foo\math\sin, | ||
- | use const foo\math\PI, | + | use const foo\math\PI, |
// 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 }; |
</ | </ | ||
=== Mixed Use Declarations === | === Mixed Use Declarations === | ||
- | Current namespace | + | |
+ | The current | ||
+ | |||
+ | Current namespace implementation does not allow mixed imports | ||
<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, | use function foo\math\sin, | ||
Line 102: | Line 105: | ||
</ | </ | ||
- | ===== About The Syntax Choice | + | ===== Justification |
- | The current choice for batch use syntax is basically a small variation from the current trait adaptation syntax: | + | |
- | < | + | 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 ' |
- | use A, B { | + | |
- | | + | 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 " |
- | | + | |
- | } | + | < |
+ | 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; | ||
</ | </ | ||
+ | |||
+ | 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: | ||
+ | |||
+ | < | ||
+ | use Symfony\Component\Console\Question { | ||
+ | ConfirmationQuestion, | ||
+ | ChoiceQuestion as Choice; | ||
+ | + | ||
+ | Question, | ||
+ | }; | ||
+ | +use Symfony\Component\Consolidation\Question\OptionQuestion; | ||
+ | </ | ||
+ | |||
+ | |||
+ | ===== 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