simple modules
ihab.awad at gmail.com
ihab.awad at gmail.com
Mon Feb 1 19:25:03 PST 2010
On Mon, Feb 1, 2010 at 10:09 PM, Allen Wirfs-Brock
<Allen.Wirfs-Brock at microsoft.com> wrote:
>> import X as ...;
>> import Y as ...;
>>
>> function f1() { /* operate on the authorities of 'X' */ }
>> function f2() { /* operate on the authorities of 'Y' */ }
>>
>> In this fashion, I cannot limit, via lexical scope, that f1 operates
>> on X but not Y, and that f2 operates on Y but not X.
>
> But the above four lines are all in the same module, that is in the same unit of source code.
Yes, but there's a difference. Consider the following:
import X as x;
import Y as y;
function f1() { /* deeply nested structure */ }
function f2() { /* deeply nested structure */ }
It is very difficult to tell whether f1() limits its authority to
using X, and f2() to using Y. Now consider:
import X as x;
import Y as y;
(import 'f1')({ x: x });
(import 'f2')({ y: y });
This is much clearer. Alternatively:
import X as x;
import Y as y;
module f1(x) { /* deeply nested structure */ }
module f1(y) { /* deeply nested structure */ }
f1({ x: x });
f2({ y: y });
achieves the same purpose, given that the 'module' keyword cuts the
lexical scope.
Absent syntactic bikeshedding (for which there will be plenty of time
:) ...) what I'm trying to show here is that a good module system
*helps* you divide up your lexical scope.
Ihab
--
Ihab A.B. Awad, Palo Alto, CA
More information about the es-discuss
mailing list