Proposal: Package aliases

Bill Baxter dnewsgroup at billbaxter.com
Wed May 14 13:43:07 PDT 2008


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.

--bb



More information about the Digitalmars-d mailing list