Import Conflict Resolution
Import conflict resolution
|
Prologue
Assumptions
Imports are private by default (and they are in DMD 0.163).
Terminology
- FQN
- Fully Qualified Name.
- visible
- The compiler acknowledges the existance of the member.
- accessible
- The compiler allows references to the member by name.
- multi-import
- A syntax/functionality which makes multiple names available in the current scope. This is what the current import does.
Problems/Issues
A: Importing 2 modules with the same symbol causes an immediate collision eg.
|
B: Changes to a module at a later date may cause a collision at a later date.
|
At later date symbol 'foo' is added to b and now the collision occurs.
Current behaviour
|
|
Current solutions
1:
|
2:
|
Opinions/pros/cons on the current solutions
1:
- PRO
- Solves the import conflict for the intended symbol.
- CON
- Does NOT solve future symbol conflicts.
- The alias is 'physically' seperate from the import.
- PRO
- Solves the import conflict for the intended symbol.
- CON
- Does NOT solve future symbol conflicts.
- Causes more verbose code.
HelmutLeitner: Proposed addition to 2/CON:
- Changing library file structure breaks application code
Proposed solutions
3: FQN Import
Don't do the "multi-import" (the import of the module members), only allow FQN access. (AKA "static import")
|
|
4: Aliasing Import
Import into a custom namespace, eg.
|
This method should also prevent import into the "secondary namespace".
This method may also force names to be fully qualified with the custom namespace id. See Solution Details below for voting on this aspect.
|
|
5: Selective Import
Allow selective import of the exact symbol which is required.
|
No other symbols would be imported or become accessible.
5U: Universal Selective Import
Same as above, but allow ANY symbol to be selectively imported. In other words:
Imports a specified symbol/entity by its base name, making it accessible by its base name in the current namespace (and only so).
|
In the case of importing modules, formally equivalent to the following aliasing import:
|
Opinions/pros/cons on the various solutions
3: FQN Import
- PRO
- Solves the import conflict for the intended symbol.
- Solves future symbol conflicts in the same module(s).
- CON
- Causes more verbose code, using FQN all the time. (could be solved by having a "using" statement along with import")
- PRO
- Solves the import conflict for the intended symbol.
- Solves future symbol conflicts in the same module(s).
- Solves the ability to force FQN usage.
- PRO
- Solves the import conflict for the intended symbol.
- CON
- It is very verbose when one wants to import many symbols from the same module.
- PRO
- Solves the import conflict for the intended symbol.
- (vs 5) No verbosity problems (just selectively import a module).
- (vs 4) Shorter syntax than the equivalent aliasing import.
- CON
- (vs 4) Does not allow renaming of the imported base name. (can be viewed as PRO :p )
Voting for Solutions
1:
2:
3: FQN Import
4: Aliasing Import- LucasGoss
- Dave
- LarsIvarIgesund
- JustinCalvarese
- JariMattiMäkelä?
- Jeremy Vight (Phr00t)
- CarlosSantander
- AndKhropov?
- ReganHeath?
- DerekParnell
- AndrewEdwards? (Tyro)
- RioshinAnHarthen?
- RémyJAMouëza?
- HelmutLeitner
- RioshinAnHarthen?
Voting on Preferred syntax for Proposed Solutions
(provide example)3: FQN import
|
|
- AndKhropov?
|
|
- Dave
- RémyJAMouëza?
|
- LucasGoss
- Dave
- JariMattiMäkelä?
- LarsIvarIgesund
- Jeremy Vight (Phr00t)
- AndKhropov?
- ReganHeath?
- GeorgWrede
- AndrewEdwards? (Tyro)
- RémyJAMouëza?
|
- LucasGoss
- Dave
- JustinCalvarese
- JariMattiMäkelä?
- CarlosSantander
- ReganHeath?
- AndrewEdwards? (Tyro)
|
- LucasGoss
- Dave
|
|
- JariMattiMäkelä?
|
|
|
- ReganHeath?
- LucasGoss
- DerekParnell
- RioshinAnHarthen?
- JustinCalvarese
|
- HelmutLeitner (please correct me on nonesense, I was not following the ng discussions and I'm not up-to-date with D development or syntax, but frustration with collisions and the need for the creation of clean namespaces without referencing modules is genuine)
Voting on Solution Details
Aliased import : #4
- Use of FQN mandatory. AKA: no multi-import. (Only the aliased module name is imported, the module members are not)
|
- DerekParnell
- BrunoMedeiros (this is essential, it doesn't make sense to be otherwise)
- CarlosSantander
- Dave
- RioshinAnHarthen?
- Prohibits use of module name in FQN
|
- RémyJAMouëza?
- DerekParnell
- Allows use of module name in FQN
|
- RioshinAnHarthen?
- CarlosSantander
- Dave