Imports in DWT
Ary Borenszweig
ary at esperanto.org.ar
Tue Mar 4 15:31:54 PST 2008
Ty Tower escribió:
> Was it java that had
>
> import dwt.graphics.*;
> and
> import dwt.graphics.Colour,Font,Cursor;
>
> this saved a lot of typing. Can it not be done here?
My guess is that it is not allowed in D for performance reason. In Java,
say you have:
---
package some.package;
import foo.*;
class SomeClass {
Bar b;
}
---
Now, to find Bar, you have to look for a file Bar.java in the directory
foo in the classpath, or in the current package. If neither of these
exist (very rare), then the compiler has to search in each java file in
the current package for a top-level class named Bar (there can be only
one top-level public class in a java file, and the name must be the same
as the class). You can see how fast lookups are in Java because of the
way it is designed.
In D, if you have
import foo.*;
Bar b;
the compiler will have to parse each file in the foo package, searching
in each of them for a public symbol called Bar. Not only that, but it
has to performe semantic analysis in each of them to resolve
compile-time stuff and see if Bar is actually being generated in
compile-time. So... a huge compilation performance impact.
(BTW, that's the reason why I hate "all" imports)
More information about the Digitalmars-d-dwt
mailing list