FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

What would be the best overall strategy for import?

 
Post new topic   Reply to topic     Forum Index -> General
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%
 5%  [ 1 ]
I don't get namespace collisions and never will - leave import alone
0%
 0%  [ 0 ]
Add an optional "static import" to safely import symbols, but all symbols must be fully qualified (FQN)
16%
 16%  [ 3 ]
Add an optional and safe "import x.y.z as n", where a short prefix is required instead of FQN
5%
 5%  [ 1 ]
add an optional and safe selective import "with x.y.z import Time, Date"
5%
 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%
 61%  [ 11 ]
Add a list of aliases after each "static import"
5%
 5%  [ 1 ]
Total Votes : 18

Author Message
kris



Joined: 27 Mar 2004
Posts: 1494
Location: South Pacific

PostPosted: Sun Jul 09, 2006 3:45 am    Post subject: What would be the best overall strategy for import? Reply with quote

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
View user's profile Send private message
h3r3tic



Joined: 30 Mar 2004
Posts: 261
Location: Torun, Poland

PostPosted: Sun Jul 09, 2006 5:14 am    Post subject: Reply with quote

I believe that Python got it right:
http://docs.python.org/ref/import.html
Back to top
View user's profile Send private message MSN Messenger
JJR



Joined: 22 Feb 2004
Posts: 1104

PostPosted: Sun Jul 09, 2006 11:17 am    Post subject: Reply with quote

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. Confused 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
View user's profile Send private message
brad
Site Admin


Joined: 22 Feb 2004
Posts: 490
Location: Atlanta, GA USA

PostPosted: Sun Jul 09, 2006 11:38 am    Post subject: Reply with quote

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
View user's profile Send private message
sean



Joined: 24 Jun 2004
Posts: 609
Location: Bay Area, CA

PostPosted: Sun Jul 09, 2006 1:39 pm    Post subject: Reply with quote

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
View user's profile Send private message
JJR



Joined: 22 Feb 2004
Posts: 1104

PostPosted: Sun Jul 09, 2006 1:59 pm    Post subject: Reply with quote

At this point, I'd accpet either syntax (with or from) if it just meant we got to have it in the language. Confused

-JJR
Back to top
View user's profile Send private message
phoenix



Joined: 06 Mar 2005
Posts: 68

PostPosted: Tue Jul 11, 2006 3:38 pm    Post subject: Reply with quote

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
View user's profile Send private message
kris



Joined: 27 Mar 2004
Posts: 1494
Location: South Pacific

PostPosted: Tue Jul 11, 2006 6:28 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> General All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group