Problem with one-class-per-file approach
kris at theredhead.nl
Mon Mar 8 08:56:09 PST 2010
Allow me to introduce myself, I'm Kris and new to this list and the D language in general, but have well over 20 years of programming experience using several other languages ranging from Wozniaks' integer basic to Hejlsbergs' c#.
All in the package "red.xml"
Being used to (and really liking!) the one-class-per-file approach, I instinctively created the classes in seperate files. When attempting to compile a simple test program however it quickly became totally unrealistic to use the one-class-per-file approach because I had to import each and every single file seperately in order to get a working build. When I moved all the classes into a single module (red.xml.xmldom) it worked flawlessly but I would really like to have the best of both approaches.
Is it possible to split the files up to use one class per file again, but add a red.xml.xmldom module imports and exposes them somehow?
I was hoping it'd be something like the following in the red.xml.dom module:
But that doesn't seem to work (I get a whole bunch of "module ... is in multiple defined" errors).
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. The generated commandline statement looks like this:
dmd -of/Users/kris/Developer/D/xml-tests/main -unittest /Users/kris/Developer/D/xml-tests/main.d /Users/kris/Developer/D/xml-tests/red/generic/linkedlist.d /Users/kris/Developer/D/xml-tests/red/xml/xmlnode.d /Users/kris/Developer/D/xml-tests/red/xml/xmldocument.d /Users/kris/Developer/D/xml-tests/red/xml/xmlattribute.d /Users/kris/Developer/D/xml-tests/red/xml/xmlattributelist.d /Users/kris/Developer/D/xml-tests/red/xml/xmlelement.d /Users/kris/Developer/D/xml-tests/red/xml/xmltextnode.d /Users/kris/Developer/D/xml-tests/red/xml/xmlcomment.d /Users/kris/Developer/D/xml-tests/red/xml/xmlcdatasection.d /Users/kris/Developer/D/xml-tests/red/xml/xmlnodelist.d /Users/kris/Developer/D/xml-tests/red/xml/dom.d
dmd -ofmain -unittest main.d
I've also tried versions omitting the dom.d (same errors), and adding only dom.d (lots of "identifier ... is not defined" errors), but nothing works the way I'd hope and/or expect.
Is there any clean way to do this?
I can make my sourcecode available if anyone would like that (for the build tool as well).
More information about the Digitalmars-d-learn