Proposal: Package aliases
Bill Baxter
dnewsgroup at billbaxter.com
Wed May 14 16:57:51 PDT 2008
Yigal Chripun wrote:
> 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?
I was just trying to use something a lot of people would recognize. A
better example would be dwt:
import dwt.DWT;
import dwt.dwthelper.Runnable;
import dwt.widgets.Display;
import dwt.widgets.Shell;
import dwt.widgets.CoolBar;
import dwt.widgets.CoolItem;
import dwt.widgets.ToolBar;
import dwt.widgets.ToolItem;
import dwt.events.ControlEvent;
import dwt.events.ControlAdapter;
import dwt.layout.FillLayout;
import dwt.layout.FormLayout;
import dwt.layout.FormData;
import dwt.layout.FormAttachment;
import dwt.layout.GridLayout;
import dwt.layout.GridData;
import dwt.graphics.Rectangle;
import dwt.opengl.GLCanvas;
import dwt.opengl.GLData;
It would be nice if the redundancy could be reduced somehow.
> a related matter: why not separate the logical namespaces from the
> actual file system organization? something like .net does with its
> namespaces vs. assemblies?
Can you explain what .NET does a little more? I'm not familiar with it.
--bb
More information about the Digitalmars-d
mailing list