Import concerns revisited

Bill Baxter Bill_member at pathlink.com
Mon Jul 10 18:05:40 PDT 2006


Just wanted to join in to make 2 quick comments:

1) regarding "static import foo.bar"

People seem to saying the 'static' is rather meaningless as a word in this
context.  But think of it this way:  "static" the English word means
"stationary" "showing little changing".  In that sense a static import is an
import that doesn't change or move the name of the module being imported.
Although you're *importing* it (bringing it into the current namespace), you're
not actually *moving* it into the current namespace.  foo.bar.baz remains
foo.bar.baz, rather than being moved into the current namespace as baz.  So in
that sense, "static" actually seems to make some sense here, I think.  (not
saying I like it, though.  "Static" is still overused, and fqn imports should be
the default and have the simplest syntax, since they're the safest from a SE
standpoint.)

2) Regarding ways to avoid new keywords 'as' or 'from'

'=' is another option for avoiding new 'as'/'from' keywords.

Someone suggetsed 
import foo.bar : mybar
I think as an alternative to 
import foo.bar as mybar

I kind of like that as a way to avoid introducing a keyword, but maybe '=' would
make more sense as in:

import mybar = foo.bar

Or to list a few aliases:

import foo.bar : mybaz = baz, myblip = blip, bork

Or use 'with' in conjuction with '='
with foo.bar import mybaz = baz, myblip = blip, bork

I'm not wild about 'import' getting stuck in the middle there, but it's the same
thing as Python's:  
from foo.bar import mybaz as baz, myblip as blip, bork
which most people don't seem to mind.  Using '=' makes it shorter though, and
much shorter than it would be with 'alias' stuck in there somehow.

I think Python's import rules are generally quite sane, and D could do far worse
than to copy Python's rules wholesale; however, note that Python 2.5 is getting
a new feature related to importing relative to the current module:
http://docs.python.org/dev/whatsnew/pep-328.html
--

Actually -- back to the avoiding new keywords discussion -- I'm curious why you
can't just introduce 'as' or 'from' as new keywords that are ONLY keywords in an
import statement.  Assuming you make the grammatical construct always begin with
'import' the production rules for the grammar should still be simple.

Regards,
'bill the lurker'





More information about the Digitalmars-d mailing list