Making D Lang More easy.
Matthew Ong
ongbp at yahoo.com
Mon May 16 03:30:03 PDT 2011
On 5/12/2011 2:23 AM, Walter Bright wrote:
Hi Walter,
>
> Not sure what you mean by more complex than Java. The order of imports
> in D is not important.
Hmm... Someone more experience in Java and also D might want to update
this URL and help some new Java To D developer to figure out the import
subtle differences
http://prowiki.org/wiki4d/wiki.cgi?JavaToD
> But it is quite common in Java to import >only
>exactly what you use, though I think that that's at least partially to
>avoid
>symbol clashes, and D doesn't work quite the same way in that regard.
Yes. I agrees with Jonathan. Please take a look at these 2 blocks bellow.
In Java,
import java.util.*; // for LinkedList / HashMap
import java.sql.*; // for JDBC API
class MyTable{
void read(){
... // Obtain ResultSet
Date date=rs.getDate(1); // this line will always cause
compilation error because both java.util & java.sql package has Date class.
}
void readFixed(){
... // Obtain ResultSet
java.util.Date date=rs.getDate(1); // this will fixed the
compilation error while still keep both the imports.
}
}
http://www.digitalmars.com/d/2.0/module.html
module A;
void foo();
void bar();
------------------------
module B;
void foo();
void bar();
------------------------
module C;
import A;
void foo();
// .... Due to the fact that there is only one D source file per module,
and from what I can see, there are normally many
functions/classes/others... in between here. The user of that function
might have forgotten about the foo defined above.
void test()
{
// the line below is really >dangerous< and might have been missed
out because it is NOT flagged. Such things are always flag within Java
and also google Go and maybe c/c++. Hopefully this will be flag as
compilation erro to others kind of syntax.
foo(); // C.foo() is called, it is found before imports are searched
bar(); // A.bar() is called, since imports are searched
}
--
Matthew Ong
email: ongbp at yahoo.com
More information about the Digitalmars-d
mailing list