Import concerns revisited

Dave Dave_member at pathlink.com
Mon Jul 10 19:47:13 PDT 2006


Walter Bright wrote:
> Dave wrote:
>> I'm not sure what exactly Kris said, but imports are ubiquitous.
>  > Not used as much as loops of course, but they are used in every program.
> 
> Yes, they are ubiquitous. But the renaming of imported symbols? I'm not 
> convinced that is at all ubiquitous, or that it is very desirable in any 
> but unusual cases.

Because when libs. and the projects that use them get bigger it will 
probably get much more desirable, and not for just unusual cases.

For example, you can/have to use FQN in C# w/o an 'import', but through 
the 'using' directive can abandon the FQN:

System.Data.OleDb.OleDbCommand cmd = new 
System.Data.OleDb.OleDbCommand(...);

or

using System.Data.OleDb;
...
OleDbCommand cmd = new OleDbCommand(...);

and then:

using olecmd = System.Data.OleDb.OleDbCommand;
using odbcmd = System.Data.Odbc.OdbcCommand;
...
olecmd ocmd = new olecmd();
...
odbcmd dcmd = new odbcmd();

the last form is like the from / as syntax.

I like it - it can *really* cut down on the amount of superfluous code 
you have to write / scan / read for things like OleDbCommand, which are 
often used all over the place in a C# 'module'.

Because of the size of the .NET library, namespaces like 
'System.Data.OleDb' (or worse) are very uncommon.

> 
>>  > 2) how much power it adds
>>
>> It adds the ability to import specific symbols - a quite powerful 
>> addition to import I think.
> 
> But that power already exists. The discussion is now about whether two 
> statements should be combined into one or not. The power is the same.

Yes but the proposed syntax also allows things like this:

import from a.very.popular.db.lib select as dbopen, insert as dbclose;

rather than

static import a.very.popular.db.lib;
alias a.very.popular.db.lib dblib;
alias dblib.open dbopen;
alias dblib.close dbclose;

Actually I think there is another criteria: 7) Does a feature build-in 
something useful or more convenient for large scale development that C 
and C++ don't have, or more importantly, Java and C# _do_ have.

The 'from' / 'as' syntax does that as well, again IMHO.

Walter, only you know how tough it is to implement. If it would be a 
total PITA to implement over 'static import' than I completely 
understand, especially at this stage.

- Dave



More information about the Digitalmars-d mailing list