Proposal: Package aliases

Yigal Chripun yigal100 at gmail.com
Wed May 14 16:06:44 PDT 2008


Bill Baxter wrote:
> Bill Baxter wrote:
>> Using packages for modules in D is good.  It prevents name clashes. 
>> But you need a unique package name.  The more unique (i.e. longer),
>> the more a pain it becomes to use a bunch of modules from that package.
>>
>> For example in Java, all of SWT is in the org.eclipse.swt package. 
>> For DWT Frank just shortened the package to "dwt" because having to
>> type something longer so many times would be a pain (and I guess
>> because dwt isn't really an Eclipse project.)
>>
>> Anyway, putting code inside uniquely named packages is a good thing.
>> But nobody wants package names to be very long, because you have to
>> type them every time you do an import.  Hence we have "std", and
>> "tango". The longest "vendor" package name I know of is "derelict". 
>> And quite a bit of D code out there uses no package at all.
>>
>> I think it would be convenient if packages could be aliased.
>>
>> Right now this is not possible:
>>
>>   alias tango.io tio; // this alias actually compiles, but...
>>   import tio.Stdout;  // import using it doesn't work
>>
>> (Note for the Tango non-savvy: import tango.io.Stdout *is* valid.)
>>
>> So my proposal is simply to make the above code work.
>> I was actually mildly surprised that it didn't.
>>
>> If we had this then people would be more free to name their packages
>> whatever they like, comfortable in the knowledge that users will only
>> have to type the full package name once.
> 
> Another possibility would be a new form of "with" for packages:
> 
> with(dwt.widgets) {
>   import Button,Control,Display,Shell;
> }
> 
> --bb

I like the general idea, but how many times do you need to import a
module like tango.io.Stdout in a file?
a related matter: why not separate the logical namespaces from the
actual file system organization? something like .net does with its
namespaces vs. assemblies?




More information about the Digitalmars-d mailing list