Some Basic Questions

Sean Kelly sean at f4.ca
Tue Aug 15 08:39:18 PDT 2006


Jay Kyburz wrote:
> 
> I have each of my classes in separate source files. the files are named the 
> same as the class.  Is it true that each source files is compiled to a 
> separate module? 

Source files and modules are effectively the same thing.  I think you 
could technically have two separate files with the same module name to 
split up large modules, but I consider that more of a hacker trick than 
anything.

> That a module needs to import any other module to access its classes?

Yes.

> These modules are the obj files right? 

Yup.

> Where is it getting the name of the modules from?

If no module name is supplied then it is assumed to be the same as the 
file name.  And in general, it is a bad idea to use a different file 
name from what you want the module name to be, because import statements 
reference the file name, not the module name (confusing, huh?).  If you 
want your module to be semantically grouped with other modules, you can 
specify a package name as a part of the module name. ie.

     // filename should be 'mymodule.d'
     module mymodule;

     // file should be 'mypackage\subgroup\mymodule.d'
     module mypackage.subgroup.mymodule;

In the latter case, you'd add the directory the 'mypackage' directory 
lives in into your include path.  Importing it would be:

     import mypackage.subgroup.mymodule;

 > My source files are
> capitalized but from the looks of things module names need to be lowercase. 
> Or at least the first letter needs to be. eg. TaskArea class is save in 
> TaskArea.d but I need to import taskArea to access the class.  By disabling 
> clean I see that this is the name of the generated obj file. How come it 
> changes case on me? Should I stick with this naming convention for my 
> sources?

That's a matter of opinion.  According to the D style guide, module 
names should be lowercase.  But this is just a convention, and not 
everyone uses it.  Mango, for example, uses CamelCase module names 
similar to Java.  Whatever you choose, however, the capitalization of 
the module name, file name, and import statement should all be the same.

> Also, how does the dot syntax work?

See above.  Each dotted segment refers to a subdirectory name, with the 
last bit referring to a file name.  This directory chain is expected to 
hang off of one of the directories in your include path (whych can be 
set at compile time by adding a '-Ipathname' in addition to modifying 
sc.ini).

> I've downloaded and using TinyXML. I've dropped the sources in a folder 
> called TinyXML. To access this i need to import tinyxml.tinyxml not 
> TinyXML.tinlyxml. So the dot syntax is used to find objs in subfolders? And 
> it also requires lowercase?

Case shouldn't matter on Windows, but as above, the capitalization used 
in your import statement should match the capitalization of the path 
name.  I'm not sure why the capitalized form isn't working, though I've 
never tried to capitalized the path portion of the name.

> But then what is with std.stdio? I don't see an std folder? Is this a special 
> case?

The std folder is in dmd\src\phobos, which should be the first directory 
in your include path listed in dmd\bin\sc.ini.

> When i import dwt.all for GUI, it seems to be compiling all of it it every 
> time I build. Do I really need to recompile all of dwt every time i build?

Assuming you're using Build, it should build an object file for each .d 
file needed for the application if the object file doesn't already exist 
and put that file in the same directory as the .d file it corresponds 
to.  You can tell Build to get rid of the object files when it's done 
with them (thus forcing them to be re-built each time) by adding a 
'-clean' switch at the command-line, but it isn't required.


Sean



More information about the Digitalmars-d-learn mailing list