Import concerns revisited
Bill Baxter
Bill_member at pathlink.com
Tue Jul 11 01:52:50 PDT 2006
In article <e8vlsn$19vu$1 at digitaldaemon.com>, Walter Bright says...
>
>Bill Baxter wrote:
>> 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
>
>Thanks for the reference. Looks like they found that relative imports
>were a mistake, and want to move to absolute imports. D already uses an
>absolute import model, so there's no issue there for us.
I think D also has the edge on Python in terms of uniform syntax for importing
modules as well as functions. In Python to import a module it's:
import modulename.submodulename
but for functions or classes in a module you have to do
from modulename import functionname
D's way is better. No matter what 'blah' is, if you want to import it, it's
'import blah.blah.blah;'.
Python's lack of a standard, simple way to provide module-level protection is
annoying, too. It makes it hard to tuck your implementation details out of the
way. For example, if module A uses some.really.massive.library in it's
implementation and imports lots of symbols from it, and I "import A", then all
the symbols A imported are visible as "A.___". It makes it difficult to
differentiate between A's implementation details and A's exports. Users just
see both thrown together in a big bag.
So really I should have said "You could do a lot worse than copying Python, but
you can definitely do a lot better." :-)
>> 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.
>
>The jargon for that is "context sensitive keywords". They prevent things
>like a clean lexical pass, mess up syntax highlighters, and generally
>cause trouble.
Been too long since I took a compiler course. But I guess I can see how it's
nice to be able to declare something unequivocally a keyword as early as
possible in the lexing phase. Thanks for the answer.
--Bill
More information about the Digitalmars-d
mailing list