Passing file handles from functions? (Changed since dmd v0.118)

Lars Kyllingstad public at kyllingen.NOSPAMnet
Thu Sep 18 04:41:01 PDT 2008


AEon wrote:
> Lars Kyllingstad wrote:
> 
>> AEon wrote:
>>> Pardon my ignorance, this is only day 3 of me reading up on D again, 
>>> but would that mean I have to place the "same" list of library 
>>> imports into every module I use, instead of defining such a list in 
>>> one "central" module, that is then imported by all the other modules?
>>>
>>> [...]
>>>
>>> So my "style guide" question?
>>>
>>> Should I refrain from using a global library include module 
>>> (aepar_global.d), to instead include the libs on a per module basis, 
>>> including only those libs the functions actually need? Or is there 
>>> some other way?
>>
>> If you use the *same* imports in every module, perhaps it makes sense 
>> to create a module that imports them all. To do this, you use the 
>> 'public import' statement, i.e. in aepar_global.d you write
>>
>>   public import std.c.stdio;
>>   public import std.c.stdlib;
>>   ...
>>
>> However, most of the time this is not true, at least not in my 
>> experience. I think it's better to keep the namespace clean and tidy 
>> by using only the imports one actually needs in each module. Private 
>> imports are the default, as Sergey pointed out.
>>
>> -Lars
> 
> Ah... I have noted how "messed up" my namespace was. Back then I ported 
> the parser code (AEstats) directly from ANSI C and v0.118 seems to have 
> been tolerant enough to let me use "import" pretty much the way I was 
> using "include" under C. You are right, I also prefer to have things as 
> clearly implemented as possible.
> 
> What surpised me, after removing the global import of libs, was that my 
> modules did not seem to need any of the libs... I find that a bit strange.

This is why D's import is much better than C's #include.

> Question: Will dmd make it pretty clear when it needs some library 
> included? I.e. the compiler shows a warning / error?

Sure, if you try to use a function/class/whatever that hasn't been 
imported, the compiler will emit an error. (It will not, however, tell 
you which module you should import to make it work.)

-Lars


More information about the Digitalmars-d-learn mailing list