Remarks about module import

Brendan Eich brendan at mozilla.org
Mon Aug 18 16:46:40 PDT 2008


On Aug 18, 2008, at 1:44 PM, ihab.awad at gmail.com wrote:

>

Hi Ihab, I'm going to respond pointedly to only part of your post.  
Please take this as a constructive riposte, intended to get at a high- 
order design bit that should not be assumed set or clear: whether  
modules should be like ES1-3's weak notion of program units or should  
be something new: purely lexical scope containers.


> By that argument, I would like to propose that a module and a
> "compilation unit" (or ES3 <Program>) be merged into one concept. This
> has the useful side effect that the loading of a top-level program
> (whatever that is, and wherever it comes from) can be re-explained
> simply in terms of the loading of a module.

This reasoning seems backwards. If modules are added in a first-class  
way to the JS, they present an opportunity to avoid the global objec  
utterly, and enforce true lexical scope. Since the Program  
nonterminal from ES1-3 is evaluated using a shared global object in  
browser embeddings, it cannot be restated using this lexical-scope- 
only idea of a module.

Why make so future-hostile a decision to enshrine today's Program  
semantics with respect to the global object? The ever-extensible  
global object topic has been bruted about as a security problem, and  
I agree it's a problem for enforcing various properties important for  
modularity and security.

Dave Herman points out that JS is evolving away from its REPL roots,  
just as Scheme did, so the ever-extensible top level is increasingly  
hopeless. One (compatible) way around this is to extend the language  
with new forms that introduce purely lexical scope.

Thus the global object, programs as source evaluated using the global  
object as the single object on the scope chain, and even all the  
hated dynamic scope forms (with, eval that can introduce bindings in  
its caller's scope) can be left in the outside-the-module penalty  
box. Compatibility requires this, in any foreseeable ES version.

Inside a module, introduced by some kind of explicit syntax, only  
lexical scope is allowed. No global properties are available. Typos  
in unqualified identifier expressions can be caught at compile time.  
Cats and dogs live together in peace ;-).

Comments?

/be
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.mozilla.org/pipermail/es-discuss/attachments/20080818/3abc7482/attachment-0001.html 


More information about the Es-discuss mailing list