View previous topic :: View next topic |
What would be the best way for import to operate? |
I'm not really sure what the issues are |
|
5% |
[ 1 ] |
I don't get namespace collisions and never will - leave import alone |
|
0% |
[ 0 ] |
Add an optional "static import" to safely import symbols, but all symbols must be fully qualified (FQN) |
|
16% |
[ 3 ] |
Add an optional and safe "import x.y.z as n", where a short prefix is required instead of FQN |
|
5% |
[ 1 ] |
add an optional and safe selective import "with x.y.z import Time, Date" |
|
5% |
[ 1 ] |
add both the "import x.y.z as n" and "with x.y.z import Date, Time" variations to cover all known issues |
|
61% |
[ 11 ] |
Add a list of aliases after each "static import" |
|
5% |
[ 1 ] |
|
Total Votes : 18 |
|
Author |
Message |
kris
Joined: 27 Mar 2004 Posts: 1494 Location: South Pacific
|
Posted: Sun Jul 09, 2006 3:45 am Post subject: What would be the best overall strategy for import? |
|
|
What we're voting on here is a strategy.
If you're not sure what the issues are, please select the first option ~ it's important that this is explained carefully to everyone, and this is how we'll figure out how well the issue is understood. There's now a document describing the some of the issues over here: http://larsivi.net/files/ImportIssues.pdf
The options noted above for selective-import and for prefixed-import are syntactic examples only, though the meaning would be consistent. For instance, the prefix-import might be "import x.y.z : z;" instead of using the word "as". Likewise, the selective-import syntax might be quite different; but with the same fundamental notion behind it.
FQN means Fully Qualified Names, and refers to this syntax:
Code: | static import lib.text.locale;
static import lib.text.convert;
auto dst = lib.text.locale.daylightSavings();
auto str = lib.text.convert.format ("?s green bottles", 10);
|
Prefixed import refers to this:
Code: | import lib.text.locale as locale;
import lib.text.convert as convert;
auto dst = locale.daylightSavings();
auto str = convert.format ("?s green bottles", 10);
|
Selective imports refers to this:
Code: | with lib.text.locale import daylightSavings, Time;
auto dst = daylightSavings();
auto time = new Time;
|
Aliased imports refers to this:
Code: | static import lib.text.locale;
alias lib.text.locale.daylightSavings daylightSavings;
alias lib.text.locale.Time Time;
static import lib.text.convert;
alias lib.text.convert convert;
auto time = new Time;
auto dst = daylightSavings();
auto str = convert.format ("?s green bottles", 10);
|
Last edited by kris on Tue Jul 11, 2006 6:20 pm; edited 1 time in total |
|
Back to top |
|
|
h3r3tic
Joined: 30 Mar 2004 Posts: 261 Location: Torun, Poland
|
|
Back to top |
|
|
JJR
Joined: 22 Feb 2004 Posts: 1104
|
Posted: Sun Jul 09, 2006 11:17 am Post subject: |
|
|
I think from is a better choice than with for selective imports.
[edit]
Oh... now I go look at the Python spec after the fact and find that it uses from. Amazingly, it looks like Python had the module system figured out already in a form very close to what is being suggested. D needs to do something about this too. |
|
Back to top |
|
|
brad Site Admin
Joined: 22 Feb 2004 Posts: 490 Location: Atlanta, GA USA
|
Posted: Sun Jul 09, 2006 11:38 am Post subject: |
|
|
I have to agree with the pro-Python sentiment here. And I agree that 'from' is more natural. Plus, we've never really thrown Python converts any love yet. Why not try to assimilate them as well.
BA |
|
Back to top |
|
|
sean
Joined: 24 Jun 2004 Posts: 609 Location: Bay Area, CA
|
Posted: Sun Jul 09, 2006 1:39 pm Post subject: |
|
|
I agree that 'from' is slightly more meaningful, yet 'with' is already a keyword that hass similar meaning to its suggested use here, so I think that may be the more practical choice. Either way, I prefer the Python-style syntax over the other options. |
|
Back to top |
|
|
JJR
Joined: 22 Feb 2004 Posts: 1104
|
Posted: Sun Jul 09, 2006 1:59 pm Post subject: |
|
|
At this point, I'd accpet either syntax (with or from) if it just meant we got to have it in the language.
-JJR |
|
Back to top |
|
|
phoenix
Joined: 06 Mar 2005 Posts: 68
|
Posted: Tue Jul 11, 2006 3:38 pm Post subject: |
|
|
I think Python like syntax (with/from, aka the selective import) is overkill. I think the FQN import ("static"..) plus an aliasing import (the "Prefixed import") would suffice. _________________ Bruno Medeiros |
|
Back to top |
|
|
kris
Joined: 27 Mar 2004 Posts: 1494 Location: South Pacific
|
Posted: Tue Jul 11, 2006 6:28 pm Post subject: |
|
|
My feeling is, and the experience with Mango et. al. has confirmed for a long period, that we could happily get by with the prefix-import alone. The syntax is effortless enough that it really shouldn't be a burden to developers, and the prefix is sufficiently distinct and managable to avoid all known collision issues.
For selective-import, I suspect the simpler "import x.y.z.Symbol;" would be just fine also. But this is entirely secondary to getting a good jump on the issue of combining an import with an alias. |
|
Back to top |
|
|
|