www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Is the module system in D fundamentally flawed?

reply z <z gg.com> writes:
In Java I don't remember seeing "forward reference to XXX" compiler error just
because I 'import' some package, but why in D there are so many such stupid
message?

And a google search also find so many bugs associated with "forward reference"

http://www.google.com/search?hl=en&q=forward+reference+to++site%3Apuremagic.com&btnG=Google+Search

So I just wondering what's the fundamental difference between D module and
Java's package system?

Is the module system in D fundamentally flawed?

I think in modern languages such as Python, Java, all the imports should JUST
WORK.  But obviously it's not the case in D. A compiler error like this is
just ridiculous: if the compiler can detect such "forward reference", why
can't it just "import" it? and why it need to report to the programmer, and
have to ask the programmer to manually fix it?

Anyone can give a summary, or guilelines on how to live with D's module system
to avoid some common mistakes.


Thanks.
Aug 17 2008
next sibling parent BCS <ao pathlink.com> writes:
Reply to z,

 In Java I don't remember seeing "forward reference to XXX" compiler
 error just because I 'import' some package, but why in D there are so
 many such stupid message?
 
 And a google search also find so many bugs associated with "forward
 reference"
 
I think this is a bug. At some point the docs say that order doesn't matter, but based on this issue, it does. I've complained about this and even suggested ways to build a compiler that basically can't have forward reference errors but nothing has happened. IIRC the comment I got back was to the effect of "to hard" or "can't be done" (hint: it can be done, I'm currently working on a compiler [that is working] that needs to resolve forward reference before it can fully lex some things.)
Aug 17 2008
prev sibling next sibling parent bearophile <bearophileHUGS lycos.com> writes:
Yes, the D module system has some bugs/problems, here some more, now I think
it's essentially an unfinished work:

http://www.digitalmars.com/d/archives/digitalmars/D/Modules_65730.html

That post if from some time ago, in the meantime I have found two more problems
in the current module system.

The first step to solve a problem is to recognize that a problem exists. I know
that then solving them may be difficult (and sometimes almost impossible) but
recognizing that they exist is necessary.

Bye,
bearophile
Aug 17 2008
prev sibling parent reply torhu <no spam.invalid> writes:
z wrote:
 Anyone can give a summary, or guilelines on how to live with D's module system
 to avoid some common mistakes.
There are several bug reports relating to this problem, so it's a well known issue. I suppose Walter doesn't see it as a high priority right now, since you can always work around it. And getting D 2.0 out done is more pressing. But yes, it does suck. It's one of those things you can hardly believe the first time you see it. Or the second or third. You just need to learn to live with it. Sooner or later it will have to get fixed. You can try to be diciplined about how your import tree looks like, that's my best suggestion. Try to avoid circular imports. Sometimes you need to some move code into a module of its own, etc. Just document it as a workaround, and change it back when time comes.
Aug 17 2008
parent reply "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
"torhu" <no spam.invalid> wrote in message 
news:g8a6iu$kg$1 digitalmars.com...
z wrote:
 Anyone can give a summary, or guilelines on how to live with D's module 
 system
 to avoid some common mistakes.
There are several bug reports relating to this problem, so it's a well known issue. I suppose Walter doesn't see it as a high priority right now, since you can always work around it.
I'm sorry, but after dealing with this for 4 years, I've come to disregard "putting everything into one module" as a valid workaround. Forward references should not exist, I don't care how hard they are to get rid of.
Aug 17 2008
parent Sean Kelly <sean invisibleduck.org> writes:
Jarrett Billingsley wrote:
 "torhu" <no spam.invalid> wrote in message 
 news:g8a6iu$kg$1 digitalmars.com...
 z wrote:
 Anyone can give a summary, or guilelines on how to live with D's module 
 system
 to avoid some common mistakes.
There are several bug reports relating to this problem, so it's a well known issue. I suppose Walter doesn't see it as a high priority right now, since you can always work around it.
I'm sorry, but after dealing with this for 4 years, I've come to disregard "putting everything into one module" as a valid workaround. Forward references should not exist, I don't care how hard they are to get rid of.
Forward references are illegal in D :-) This was the first thing I tried as a workaround for this compiler issue. It can make designing interdependent code a bit dicey at times. Sean
Aug 18 2008