Minor questions on new module BNF
domenic at domenicdenicola.com
Tue Jun 4 08:02:09 PDT 2013
From: Yehuda Katz [wycats at gmail.com]
> In general, expectations about side-effects that happen during module loading are really edge-cases. I would go as far as to say that modules that produce side effects during initial execution are "doing it wrong", and are likely to produce sadness.
> In this case, the `import` statement is just asking the module loader to download "someModule", but allowing the app to move on with life and not bother executing it. This would allow an app to depend on a bunch of top-level modules that got executed only once the user entered a particular area, saving on initial boot time.
I don't think this is correct. It is strongly counter to current practice, at the very least, and I offered some examples up-thread which I thought were pretty compelling in showing how such side-effecting code is fairly widely used today.
This isn't a terribly important thing, to be sure. But IMO it will be very surprising if
import x from "x";
executes the module "x", producing side effects, but
does not. It's surprising precisely because it's in that second case that side effects are desired, whereas I'd agree that for modules whose purpose is to export things producing side effects is "doing it wrong."
More information about the es-discuss