simple modules

David Herman dherman at
Wed Feb 3 12:38:13 PST 2010

[including the list, which got inadvertently cut]

> Yes, I understand that short import  is not "with", it just "smells"
> like "with" and like "global". Your reasons are correct for language
> implementers and I am telling about language users.

To be clear: this is not for implementers, it's for users. The point is that you can always know *statically* what is in scope. When you say

    function f() { ... }
    var x = ...
    with(obj) {

you don't know whether the references to f and x are captured by `obj' properties or not. When you say

    import * from Foo;

you know statically that f and x came from Foo. It doesn't depend on the runtime behavior of the program.

> This is exactly about promoting good style. And when I proposed some
> shortcut for "function" 2-3 years ago in this list, it was discarded
> for good-style and readability reasons.

IIRC, it was discarded because a) we couldn't agree on a color for the bikeshed, b) it was determined that it didn't add enough utility to the language that wasn't already there.

My point is that it's kind of a deal-breaker for every script on the web to have to write e.g.:

    <script type="harmony">
        import alert, document, window from DOM;

People have not had much problem writing `function' since the mesozoic era of JavaScript. But if we want to get them to use a new module system, we can't impose undue burdens simply for the sake of "promoting good style." Especially when the downsides of ignoring that good style are not all that grave.

> About burden - I see it - new item "Never use default import" will be
> added to books and code style guides after "Never use global and
> with".  And every user will need to remember one more JS quirk.

And if *I* were writing a style book, I would not say "never use default import." I would say, "if you are writing a module of a reasonable size, or with a reasonable number of imports, or if it's not particularly clear, then don't use default import. Otherwise, go to town. It's your language, do what you see fit."

It's not a JS quirk, it's actually an important feature.


More information about the es-discuss mailing list