Problem with one-class-per-file approach

bearophile bearophileHUGS at lycos.com
Mon Mar 8 13:04:17 PST 2010


Kris Herlaar:

> Allow me to introduce myself, I'm Kris and new to this list and the D language in general,

Welcome here and to D then.


> Being used to (and really liking!) the one-class-per-file approach, I instinctively created the classes in seperate files.<

D gives you the freedom, if you want, to put single classes in files, but the normal D idiom is to put related classes in a single module (if they aren't too much long).
And keep in mind that in D there are also free functions (and templates, inner functions, true closures, etc), so you don't need to use classes for everything.


> import red.xml.xmldocument;
> import red.xml.xmlnNode;
> import red.xml.xmlattribute;
> import red.xml.xmlelement;
> import red.xml.xmltextnode;
> import red.xml.xmlcomment;
> import red.xml.xmlcdatasection;
> import red.xml.xmlnodelist;
> import red.xml.xmlattributelist;

You can also write:
public import red.xml.xmldocument,
              red.xml.xmlnNode,
              red.xml.xmlattribute,
              ...
              red.xml.xmlattributelist;



>I'm compiling with the latest dmd compiler on the commandline in macos x (10.6) using a commandline tool I built in php that compiles a file "main.d" and adds all imported dependencies to the dmd commandline.<

There are several already written programs to do that :-) For example I use 'bud', there is also rdmd built in the distribution.

Bye,
bearophile


More information about the Digitalmars-d-learn mailing list