what's the difference between 'static import =' and 'import ='?

Bruno Medeiros brunodomedeirosATgmail at SPAM.com
Thu Jul 20 03:32:20 PDT 2006


Boris Wang wrote:
> "John Reimer" <John_member at pathlink.com> 写入消息新闻:e9knp5$fk1$1 at digitaldaemon.com...
>> In article <9vh8joe3sla0.1se36qil8397i$.dlg at 40tude.net>, Derek Parnell 
>> says...
>>> On Wed, 19 Jul 2006 06:14:11 +0000 (UTC), John Reimer wrote:
>>>
>>>> In article <e9k8bv$2usv$1 at digitaldaemon.com>, Boris Wang says...
>>>>> For example:
>>>>>
>>>>>    * static import io = std.stdio;
>>>>>    * import io = std.stdio;
>>>>>
>>>> Good question.  Have you tested these first to see what happens or if 
>>>> the first
>>>> even works?  I think that might answer your question.  Then you can tell 
>>>> those
>>>> of us who haven't had a chance to try yet. :)
>>>>
>>> There is no difference. They function in an identical manner.
>>>
>>>  static import XXX;
>>>  import XXX = whatever;
>>>  static import XXX = whatever;
>>>
>>> all require that 'XXX' be used to reference members in the code.
>>>
>>> However, if you decide to allow non-FQN all you have to do is *add* the
>>> line 'import XXX;' somewhere in your module and all the FQN requirements
>>> disappear.
>>>
>> Ah... ok. Good to know. I guess we have a very flexible system in place, 
>> capable
>> of accomodating several styles.  And Walter gets to have his "static 
>> import" as
>> well. :)
>>
>> -JJR
>>
>>
>>
> 
> No, I don't think so.
> 
> Something need refining.
> 
> Why not discard the sentence 'static import' ? When you need FQN to access a 
> package, just do it.
> 
> For example
> 
> int main(void)
> {
>     std.stdio.writefln("Just do it"); // not need any importing
>     ...
> }
> 
> 

I like the idea of FQN access automatically available for all modules, 
but the way I'd like that to be done is not for the compiler to try to 
implicitly search and import modules when encountering unknown names 
(like the 'std.stdio.writefln' in the example above).
Rather, the whole set of modules that a program uses could be set at the 
start, by compiler options (or the fqnall trick). This would avoid the 
name issues mentioned by pragma and Don (the "class std {...}") as well 
as allow an IDE to show completion for the available modules&packages.

-- 
Bruno Medeiros - CS/E student
http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D



More information about the Digitalmars-d-learn mailing list