Proposal: Package aliases
Fawzi Mohamed
fmohamed at mac.com
Fri May 16 01:23:40 PDT 2008
On 2008-05-14 23:29:37 +0200, Bill Baxter <dnewsgroup at billbaxter.com> said:
> Bill Baxter wrote:
>> [...]
>> 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 understand from where this idea comes, and it could be useful
especially when you start writing a module named baz, and later you
want to move it to foo.baz you can do it with minimal changes.
At the beginning I thought that it was a very good idea, but thinking
more about it I am not so sure anymore.
It would make automatic parsing, and grepping the source more complex
but you gain some typing work.
You can replace all occurences of the module using some regexp and
dired in emacs, or any other editor that supports interactive regexp
substitution on groups of files.
It is not perfect because in the worst case you are mixing qualified
accesses (that need a change from import baz to import baz=foo.baz) and
unqualified accesses (that needs import foo.baz).
One can always replace import baz with import foo.baz; alias foo.baz baz;
This is not very nice, but neither so ugly...
Of your proposals I like the first (make alias of modules usable for
other imports) much more than the with syntax. It makes things more
uniform and one might reasonably expect it to work, but as said I am
quite neutral about this feature (it will make IDE, and external tools
work more complex), but if available I would probably use it.
Fawzi
More information about the Digitalmars-d
mailing list